Sunday 22 May 2011

PostgreSQL dump and restore

Backup one database:
pg_dump dbname > outfile
or if you want to clean (drop) schema prior to create (drop databases prior to create):
pg_dump -c dbname > outfile 
Restore one database:
psql dbname < infile
Copy database from one host to another:
pg_dump -h host1 dbname | psql -h host2 dbname
Backup all databases:
pg_dumpall > outfile
Note: you can add the --clean option to drop tables before restoring

Restore all databases:
psql -f infile postgres

Possibly Related Posts

No comments:

Post a Comment