Accepting selected projects for Q2 2024 Check availability →
SERVER 02SYSTEM ONLINELAST SYNC: 03:17:44RSS 2.0 — ONLINE
HALF ASSEDTECHNICAL NOTES_
EST. 1999ISSUE 04.2BEST VIEWED AT 1024 × 768
TECHNICAL NOTES / PRACTICAL GUIDES / DATABASE OPERATIONS / RECORD 892888
[DATABASE OPERATIONS]GUIDE

Rehearsing a PostgreSQL 8.2 database restore

POSTED: 17.05.2007AUTHOR: ADMIN3 MIN READCOMMENTS: 0

A logical backup is useful when the database must be reconstructed on another installation. For PostgreSQL 8.2, use pg_dump for each database and retain the shared objects needed to recreate its ownership and permissions. Prove the procedure away from the production server.

Capture a named backup set

Use the 8.2 client tools for the 8.2 server and record their versions. A command such as pg_dump -Fc -f accounts.dump accounts produces a custom-format archive for pg_restore. Check its exit status and diagnostic output before marking the backup complete. Keep dated generations and copy completed sets off the database machine.

Include what a database dump omits

Save shared roles and tablespaces separately with pg_dumpall --globals-only, protecting the resulting file because it can contain sensitive role information. Retain server configuration, authentication rules and details of installed procedural languages or other required software. Files held outside the database need their own coordinated backup. Separate database dumps do not provide one simultaneous snapshot across every database.

Prepare an isolated target

Install a compatible server and required support libraries. Keep the test host disconnected from live mail delivery, payment processing and scheduled application jobs. Review the globals script before applying it, especially tablespace paths and existing administrative roles. Create the target database from template0 with the required encoding, and record any locale assumptions.

Restore and inspect every error

Use pg_restore -l accounts.dump to inspect the archive contents, then restore into the empty test database with pg_restore -d accounts_test accounts.dump. Read the diagnostics and check the exit status. A table listing alone does not establish that its data or constraints were restored. Run ANALYZE after loading so the planner has useful statistics.

Run application-level checks

Compare key record counts and totals, open representative records and try a controlled insert to check sequence values and permissions. Test the application using its normal database role rather than the administrator account. Measure the time from locating the backup to completing these checks. Retain a copy of the commands, versions and results so another operator can repeat the process.

RECOVERY RECORD

Keep a failed restore log as well as successful ones. Fix the backup procedure and repeat the rehearsal before assuming the next scheduled archive will be usable.

References

PostgreSQL 8.2: pg_dump

PostgreSQL 8.2: pg_dumpall

PostgreSQL 8.2: pg_restore