PostgreSQL - How to backup and restore a database?
Using Command line tool:
Backup:
pg_dump -U user_name db_name -f path/to/file_name.sql
Restore:
pg_restore -U user_name -d desintation_db_name -1 path/to/file_name.dump
Using TablePlus GUI
With TablePlus, you can backup and restore your PostgreSQL database within its GUI.
Backup:
- From welcome screen, press
Backup
- Choose your connection and database, and hit
backup
TablePlus will export a .dump
file for you to save on your computer.
Restore:
- From welcome screen, press
Restore
, - Choose your dumb file, choose connection and database, then hit restore.
TablePlus will import data from the dumb file to your selected database. You can import the dump file into an existing database or create a new database from this window.
New to TablePlus? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.