Duplicate database postgre, Quickly copy a PostgreSQL database

Begini cara cepat menduplikat database postgre dalam 1 computer. Saya udah tes untuk DB yg 2 GB lebih, selesai dalam 3 menit saja :D.

Often I need to create copies of databases so I can test a new stored procedure or if what I’m doing could get in the way of other developers.

The easiest way I’ve found to make a personal clone of a PostgreSQL database is by command line using psql, pg_dump and pg_restore. First back up the database using dump, create a new database in psql then restore the dump file to the newly created database.

psql – http://linux.die.net/man/1/psql
‘sudo -u postgres…’ means run this command as the postgres user.
‘postgres’ – the datbases user (set at install as default).

pg_dump – http://www.postgresql.org/docs/8.4/static/app-pgdump.html
-Fc creates a ‘custom format’ which is compatible with pg_restore, see the postgres docs for more info.

pg_restore – http://www.postgresql.org/docs/8.4/static/app-pgrestore.html
-d database name
-s restore schema only and don’t insert the data
-t restore only this table


sumber: http://alexharvey.eu/database/postgresql/quickly-copy-a-postgresq-database/


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s