Postgresql

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 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts