In this article, we would be discussing a simple steps on how to take replica/copy of a database within the cluster without backup and restore , it very useful if any developers want a replica of the original database for their development and testing or if you want a copy of the database before making major design change in the application tables resting on the database.
Please note that this procedure only works if you want to create a copy of the database within the cluster and not with databases on a different Greenplum cluster.
To create a replica or copy of the existing database, you can use the below command:
create database <new_database_name> template <old_database_name>;
Example
Let's take an example to explain if this actual copy's every content from the original database.
testdb=# \d List of relations Schema | Name | Type | Owner | Storage --------+------+-------+---------+--------- public | a1 | table | gpadmin | heap public | a2 | table | gpadmin | heap public | a3 | table | gpadmin | heap (3 rows) testdb=# select count(*) from a1; count ------- 10000 (1 row) Time: 106.450 ms testdb=# select count(*) from a2; count ------- 10000 (1 row) Time: 2.462 ms testdb=# select count(*) from a3; count ------- 10000 (1 row) Time: 1.953 ms testdb=#
testdb=# create database replica template testdb; CREATE DATABASE Time: 6272.622 ms
testdb=# \c replica You are now connected to database "replica" as user "gpadmin". replica=# \d List of relations Schema | Name | Type | Owner | Storage --------+------+-------+---------+--------- public | a1 | table | gpadmin | heap public | a2 | table | gpadmin | heap public | a3 | table | gpadmin | heap (3 rows) replica=# select count(*) from a1; count ------- 10000 (1 row) Time: 218.771 ms replica=# select count(*) from a2; count ------- 10000 (1 row) Time: 2.646 ms replica=# select count(*) from a3; count ------- 10000 (1 row) Time: 2.615 ms replica=#