parsed.org

Tips by tag: restore

Fixing Munged Template DB by xinu on Jan 12, 2005 10:24 AM

If you've munged your template1 database, you can rebuild it from the template0 database.

First, you must set the datistemplate attribute of template1 to false so we can drop it:

xinu=# UPDATE pg_database SET datistemplate = false WHERE datname = 'template1';
UPDATE 1
xinu=# DROP DATABASE template1;
DROP DATABASE

Next, re-create template1 using template0 as a template:

xinu=# CREATE DATABASE template1 WITH TEMPLATE = template0;
CREATE DATABASE

Then restore the datistemplate attribute of template1:

xinu=# UPDATE pg_database SET datistemplate = true WHERE datname = 'template1';
UPDATE 1
debugginggotchapostgresqlpsqlrecoveryrestoresqltemplate
Incorrect Checksum by xinu on Jan 12, 2005 10:22 AM

If you see the following when trying to load a newly transplanted database, it may be due to a difference in architecture (32-bit vs. 64-bit):

FATAL:  incorrect checksum in control file.

The moral is: never do a direct copy of the data directory. It isn't considered good practice.

64bitarchitecturedebugginggotchapostgresqlrecoveryrestore
PostgreSQL Dump & Restore by xinu on Mar 25, 2008 11:46 PM

In 7.4 (and possibly 8.1), the routine to dump and restore the entire database cluster follows:

# su - postgres
$ pg_dumpall > postgresql.dmp

Transfer the postgresql.dmp file to the target system, and then do the import:

# su - postgres
$ psql template1 < postgresql.dmp
dumpmigratepg_dumpallpostgresqlpsqlrestore
Using Your Own Template Database by cygnus on Jun 29, 2006 07:36 PM

If you have a database mytemplate that you'd like to use as a template, update its datistemplate attribute in the pg_database relation:

UPDATE pg_database SET datistemplate = 't' WHERE datname = 'mytemplate';

Then you can use it as a template when creating other databases:

CREATE DATABASE otherdb TEMPLATE mytemplate;
debugginggotchainternalspostgresqlrecoveryrestoresqltemplate
RSS