Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active November 21, 2017 00:27
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nepsilon/7628e42a5d1f356b3ab5629c7ff56aa1 to your computer and use it in GitHub Desktop.
Save nepsilon/7628e42a5d1f356b3ab5629c7ff56aa1 to your computer and use it in GitHub Desktop.
Proper way to do backup (and restore!) with PostgreSQL 🐘 β€” First published in fullweb.io issue #51

Proper way to do backup (and restore!) with PostgreSQL 🐘

Postgres provides us several options to do backup just like we want. I’ve tried several strategies in the past, and here is the one I stick to now, for both its simplicity and efficiency.

Backup your database with:

# This is using Postgres custom format
pg_dump -Fc dbname > filename

And recover it as follow:

# First create the DB with:
createdb -O owner_user dbname
# And then populate it:
pg_restore -d dbname filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment