How To Backup And Restore Postgresql Databases

Posted by Weston Ganger

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:

Article Topic:Software Development - Linux

Date:October 23, 2015

Recommended Posts