Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AkashRajvanshi/2546de19cc6579ab1f69d5f1505c3f88 to your computer and use it in GitHub Desktop.
Save AkashRajvanshi/2546de19cc6579ab1f69d5f1505c3f88 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