Drupal website specialists. Call us about your project on (02) 8006 3402

How to copy a Postgres database

Posted 03/February/2011 by neubreed

To make a copy a Postgres database, log into a SSH terminal and issue the following commands. pg-user-name is the postgres database user name in these examples, so yours may differ

First dump a copy of the table to a file

pg_dump -U pg-user-name -c db_name > db_name_dump

Then create a new database

createdb -U pg-user-name db_name_2010

Then import the previously dumped file into the new database

pgsql -U pg-user-name db_name_2010 < db_name_dump