Cloning a database is very easy in PostgreSQL. Use the below statement to clone the database. CREATE DATABASE TEMPLATE = ; Give the database name you want to clone in the place of Source database. PostgreSQL will take the database as a template and copy all the objects in that database to new database. Example :- postgres=# create database source; CREATE DATABASE postgres=# \c source You are now connected to database “source” as user “postgres”. source=# create table source(id text); DEBUG: building index “pg_toast_17241_index” on table “pg_toast_17241” CREATE TABLE source=# insert into source values(‘SOURCE DATABASE’); INSERT 0 1 source=# source=# create database TARGET TEMPLATE=source; CREATE DATABASE source=# \c target You are now connected to database “target” as user “postgres”. target=# target=# \d List of relations Schema | Name | Type | Owner ——–+——–+——-+———- public | source | table | postgre...
The greater our knowledge increases, the greater our ignorance unfolds.