Home

Awesome

clone_schema

clone_schema is a PostgreSQL utility that makes a copy of a given schema (DDL and/or DATA). It is based on the Community version of PostgreSQL. It works on most Linux distros and Windows versions. It also runs on PostgreSQL in the cloud (AWS, GCP, MS Azure).

Handles following objects:

<br/>

Arguments:

<pre>source schema Required: text - schema name</pre> <pre>target schema Required: text - table name</pre> <pre>ENUM list Required: One of 'DATA','NODATA','DDLONLY'</pre> <pre>ENUM list Optional: 'NOOWNER','NOACL','VERBOSE','FILECOPY'</pre>

By default, ownership and privileges are also cloned from source to target schema. To override, specify NOOWNER and/or NOACL (similar to how pg_dump works). When NOOWNER is specified, the one running the script is the default owner unless overridden by a SET ROLE command before running this script. You may get faster results copying data to/from disk instead of in-memory copy. FILECOPY is a workaround for tables with complex UDT-type columns that fail to copy. It only works for On-Prem PG Instances since it relies on using the COPY command to write to and read from disk. <br/><br/>

Clone the schema with no data: <br/>

select clone_schema('sample', 'sample_clone', 'NODATA');

<br/>

Clone the schema with data: <br/>

select clone_schema('sample', 'sample_clone', 'DATA');<br/> select clone_schema('sample', 'sample_clone', 'DATA','VERBOSE'); -- show row copy progress

<br/>

Just generate DDL: <br/>

select clone_schema('sample', 'sample_clone', 'DDLONLY');

In this case, standard output with "INFO" lines are the generated DDL. <br/><br/><br/> The schema_object_counts.sql file is useful for validating the cloning results. Just run it against source and target schemas to validate object counts after changing default schema name, sample. <br/><br/>

Regression Testing Overview

Regression Testing is done in the following order:

Assumptions

Limitations

<br/> Sponsor: http://elephas.io/ <br/> <br/> Compare cloning with EnterpriseDB's version that only works with their Advanced Server: https://www.enterprisedb.com/edb-docs/d/edb-postgres-advanced-server/user-guides/user-guide/11/EDB_Postgres_Advanced_Server_Guide.1.078.html