Sunday, June 12, 2016

Restore PostgreSQL Database

Without having to use tools like pgAdmin, you can backup and restore database using console command


Restore using pg_restore

this command will restore database from dmp file, please make sure you have create a database first, lets say that the database name is "dbname"
pg_restore -d dbname backupfile.dmp -v

sometimes for large database the amount of time required to restore database is a bit long, you can speed it up by adding -j attributes followed by the number of concurrent process you want to run, lets say that I want to run 3 concurrent process for this restore, the command will be like this
pg_restore -d dbname backupfile.dmp -v -j 3

Restore using psql

this command will restore database from sql file
psql dbname < backupfile.sql

Restore using pg_restore from compressed file in gz format

to restore database from a compressed file you can either unzip it first and restore it with the above command, or you can simply use this commands
gunzip -c backupfile.gz | psql dbname

No comments :

Post a Comment