How to restore a postgresql database from dumpall backup

If your dump was performed with the “–clean” option, you can skip the reinitializing of your databases to avoid duplicating data. This option, used with the “pg_dumpall” command will cause the restore to clean out all the objects in the database before performing the restore. If you didn’t include this option, then just delete the data directory and reinitialize the database as shown below.

* Stop the postmaster service.

PGDATA=/var/lib/pgsql/data/ pg_ctl stop
or “/etc/init.d/postgres stop” if you have fancy init scripts.

* Delete the data directory

rm -rf /var/lib/pgsql/data

* Run initdb

/etc/init.d/postgres initdb

* Give yourself some access

edit pg_hba.conf
change “ident” to “md5″ for local connections

* Start the database

PGDATA=/var/lib/pgsql/data/ pg_ctl start
or “/etc/init.d/postgres start” if you have fancy init scripts.

* Restore the data

psql -U postgres -f pg_dumpall_file postgres

The dump file is a plain text list of commands that restores all objects, or specific parts of the database if just used dump instead of dumpall.

Posted by admica   @   23 October 2009

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Disable oplocks in a heterogeneous Samba / NFS environment
Next Post
Load virtual tape drives directly »
Powered by Wordpress   |   Lunated designed by ZenVerse