Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maikeruit/b702e2c5de22871428da70c09a4da3a2 to your computer and use it in GitHub Desktop.
Save maikeruit/b702e2c5de22871428da70c09a4da3a2 to your computer and use it in GitHub Desktop.
PostgreSQL: dump and restore (to db with different name and roles even)

Postgres Export and Import

Export

pg_dump -U [superuser] -Fc [dbname] > db.dump

Import

This syntax allows importing to a database with the name of your choice.

Create the database (if it does not exist):

createdb -T template0 [dbname]

Import:

pg_restore --clean --if-exists --no-acl --no-owner --verbose -d [dbname] -U [superuser] db.dump

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment