Backup and Restore Postgres Using pg_dump and psql

This is how you backup your Postgres Database

To Backup

1
pg_dump --host=localhost --port=5432 --username=postgres --file=YOUR_FILENAME.sql YOUR_DB_NAME

There are other options such as if you’re interested only on the structure then you can add:

1
pg_dump --host=localhost --port=5432 --username=postgres --schema-only --format=p --create --inserts --file=YOUR_FILENAME.sql YOUR_DB_NAME

To Restore

1
psql -Upostgres -hlocalhost YOUR_DB_NAME < YOUR_FILENAME.sql
This entry was posted in Database, PostgreSQL. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


8 × nine =