Last Updated: February 25, 2016
·
2.34K
· jlucasps

Quick dump/restore PostgreSQL database

Create a dumb passing host address, username, file name to be exported, and database name:
Considering you are logged in server machine (localhost)

pg_dump -i -h localhost -U postgres -F c -b -v -f "bkp_filename_to_export.bd" my_database_production

Copy file from server from server to your machine:

scp <server-user>@<servier-ip>:/path/to/bkp_filename_to_export.bd .

Restore database in your local machine, specifying your host address, username, database name, and file name of the dumb file.

pg_restore -i -h localhost -U postgres -d my_database_production -v "bkp_filename_to_export.bd"