PostgreSQL Backups and Migration

From Littledamien Wiki
Revision as of 17:46, 16 February 2016 by Video8 (talk | contribs) (Created page with "Category:PostgreSQL Category:Web Development == database snapshot == <syntaxhighlight lang="bash"> $ pg_dump -h hostname - d dbname -U username > mysnapshot.sql </syn...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

database snapshot

$ pg_dump -h hostname - d dbname -U username > mysnapshot.sql

The password can be included in the command above, otherwise you'll be prompted for the password.[1]

It's also possible to compress the dump:

$ pg_dump -h hostname - d dbname -U username | gzip > mysnapshot.gz
$ gunzip -c mysnapshot.gz | psql dbname

Restoring a dump

$ psql dbname < mysnapshot.sql

Notes

  1. SQL Dump PostgreSQL 8.3.23 documetation