Copying database objects from a local source to a target v15
There are two functions you can use with EDB Clone Schema to perform a local copy of a schema and its database objects:
localcopyschema
— This function copies a schema and its database objects from a source database into the same database (the target) but with a different schema name from the original. Use this function when the source schema and the copy will reside within the same database. See localcopyschema for more information.localcopyschema_nb
— This function performs the same purpose aslocalcopyschema
but as a background job, which frees up the terminal from which the function was initiated. This function is referred to as a non-blocking function. See localcopyschema_nb for more information.
Performing a local copy of a schema
The localcopyschema
function copies a schema and its database objects in a local database specified in the source_fdw
foreign server from the source schema to the specified target schema in the same database.
The function returns a Boolean value. If the function succeeds, then true
is returned. If the function fails, then false
is returned.
The source_fdw, source_schema, target_schema
, and log_filename
are required parameters while all other parameters are optional.
Parameters
source_fdw
Name of the foreign server managed by the postgres_fdw
foreign data wrapper from which to clone database objects.
source_schema
Name of the schema from which to clone database objects.
target_schema
Name of the schema into which to clone database objects from the source schema.
log_filename
Name of the log file in which information from the function is recorded. The log file is created under the directory specified by the log_directory
configuration parameter in the postgresql.conf
file.
on_tblspace
Boolean value to specify whether to create database objects in their tablespaces. If false
, then the TABLESPACE
clause isn't included in the applicable CREATE
DDL statement when added to the target schema. If true
, then the TABLESPACE
clause is included in the CREATE
DDL statement when added to the target schema. The default value is false
.
verbose_on
Boolean value to specify whether to print the DDLs in log_filename
when creating objects in the target schema. If false
, then DDLs aren't printed. If true
, then DDLs are printed. The default value is false
.
copy_acls
Boolean value to specify whether to include the access control list (ACL) while creating objects in the target schema. The access control list is the set of GRANT
privilege statements. If false
, then the access control list isn't included for the target schema. If true
, then the access control list is included for the target schema. The default value is false
.
worker_count
Number of background workers to perform the clone in parallel. The default value is 1
.
Example
This example shows the cloning of schema edb
containing a set of database objects to target schema edbcopy
. Both schemas are in database edb
as defined by local_server
.
The example is for the following environment:
- Host on which the database server is running:
localhost
- Port of the database server:
5444
- Database source/target of the clone:
edb
- Foreign server (
local_server
) and user mapping with the information of the preceding bullet points - Source schema:
edb
- Target schema:
edbcopy
- Database superuser to invoke
localcopyschema: enterprisedb
Before invoking the function, database user enterprisedb
connects to to database edb
:
The following displays the logging status using the process_status_from_log
function:
Results
After the clone is complete, the following shows some of the database objects copied to the edbcopy
schema: