PostgreSQL Backups and Point-in-Time Recovery: Test Your Restores
A practical guide to PostgreSQL backups: base backups, WAL archiving, point-in-time recovery steps, RDS PITR and how to prove your restores work.
A backup you have never restored is a hope, not a backup. This guide covers the building blocks of PostgreSQL backup and point-in-time recovery (PITR), and, more importantly, how to prove they work before an incident forces the question.
1. Logical vs physical backups
- Logical (
pg_dump/pg_dumpall): portable, good for single databases, version upgrades and small to medium data. Slower to restore on large databases and no point-in-time recovery. - Physical (
pg_basebackupor a tool such as pgBackRest or WAL-G): copies the data directory, fast to restore at scale, and combined with archived WAL gives PITR.
Most production systems use physical backups plus WAL archiving, and keep periodic logical dumps for portability.
2. Enable WAL archiving
PITR works by restoring a base backup and replaying archived WAL up to a chosen moment.
# postgresql.conf
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'
Monitor archiving: failed archives make WAL pile up on disk and break your recovery window. Alert on pg_stat_archiver.failed_count increasing and on the age of the last successful archive.
SELECT archived_count, failed_count, last_archived_time, last_failed_time
FROM pg_stat_archiver;
3. A point-in-time recovery, step by step
- Stop PostgreSQL on the restore target and move the old data directory aside.
- Restore the most recent base backup taken before your target time.
- Tell PostgreSQL how to fetch WAL and where to stop:
# postgresql.conf (or postgresql.auto.conf) on the restore target
restore_command = 'pgbackrest --stanza=main archive-get %f "%p"'
recovery_target_time = '2026-10-30 09:41:00+00'
recovery_target_action = 'promote'
- Create an empty
recovery.signalfile in the data directory (PostgreSQL 12+) and start the server. - Check the logs for the recovery target being reached, then verify data before pointing applications at it.
Always restore to a new server first. Overwriting production in a panic turns one problem into two.
4. On RDS and Aurora
Amazon RDS takes automated backups and retains transaction logs, so you can restore to any second within the retention period. A restore always creates a new instance with a new endpoint, so plan how applications switch over. Automated backups are tied to the instance, so take manual snapshots (and copy them to another Region or account) for long-term and DR needs. Check current limits for maximum retention in the AWS documentation.
5. Prove it: automated restore tests
Schedule a job that, at least monthly (weekly for critical systems):
- Restores the latest backup to a throwaway server.
- Replays WAL to a recent timestamp.
- Runs sanity checks: row counts on key tables, newest record timestamps, application smoke queries, and integrity checks such as
pg_amcheck. - Records the elapsed time. That is your measured RTO.
- Destroys the server and reports pass/fail to your alerting system.
6. Policies that save you later
- Encrypt backups and store them in a different account or Region than production.
- Use immutability or object-lock features so ransomware or a mistaken delete cannot erase history.
- Define retention by business need and compliance, not by default settings.
- Document who can restore and how, and practise it with the on-call team.
Checklist
- Base backups plus continuous WAL archiving.
- Alerts on archive failures and backup age.
- A written, rehearsed PITR runbook.
- Automated restore tests with measured RTO.
- Off-account, encrypted, immutable copies.
Enjoyed this?
I write about PostgreSQL, AWS and database reliability. Have a question or a similar problem to solve?