How To Backup And Restore Postgresql Databases

Posted by Weston Ganger on October 23, 2015

Its handy to know how to backup and restore your databases in postgresql from the command line

Backup / Restore a Single Database

# If you dont have permissions on your current user login switch to postgres user first
sudo su - postgres

# To Backup
pg_dump your_database_name > backup_file_name

# To Restore
createdb your_database_name
psql your_database_name < backup_file_name

Backup / Restore All Databases on the Server

# To Backup All
pg_dumpall > backup_file_name

# To Restore All with the default database
psql -f backup_file_name postgres

# To Restore All with the default database of current user
psql -f backup_file_name $USER

Related External Links:

Posted in Linux and Tagged with database postgresql backup restore 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts