Lesson 6 of 9 · 23m
Disaster Recovery Drills: Restore Before You Need It
Designing RPO and RTO honestly, building a restore runbook, and rehearsing corruption, host loss, and bad deploy recovery so the first drill is not the real incident.
Nobody cares how elegant your backup diagram is at 03:40 when the primary volume is gone. They care about two numbers: how much data can we lose, and how long until the application works again. Those are RPO and RTO. Most teams discover their real RTO during the disaster because it includes credentials, provisioning, restore, WAL replay, validation, and traffic movement.
Write the numbers as operational requirements
RPO: 5 minutes of committed transactions; RTO: 60 minutes to application traffic
Restore scope: full cluster, one zone lost; success: health checks pass and audit counts matchA five-minute RPO cannot depend on nightly base backups alone; WAL archiving or continuous backup must be healthy. A sixty-minute RTO cannot depend on an untested restore over a saturated network. Decide what can lag, too — search indexes and reporting tables often can.
A runbook is executable, not inspirational
# PostgreSQL full-cluster restore
1. Freeze deploys, disable writers, and record the last known good timestamp.
2. Provision the replacement host with the same major version and locale.
3. Restore the latest base backup before the target and verify required WAL exists.
4. Configure restore_command plus recovery_target_time; start PostgreSQL and watch recovery.
5. Validate, promote, switch endpoint, and enable writers gradually.Every step should name the system, command, owner, and verification. "Restore backup" is not a step; it is a wish.
Drill the failures that actually happen
Useful scenarios include:
- Host loss: the primary is gone; promote a standby or restore elsewhere.
- Logical corruption: a bad deploy deleted valid rows; use PITR before the deploy.
- Credential or configuration loss: secrets,
pg_hba.conf, certificates, or endpoint configuration are unavailable.
Use production-like size at least occasionally. A 5 GB test database hides transfer time, memory pressure, and boredom-induced mistakes during multi-hour recovery.
Measure the drill honestly
00:00 incident declared; 00:07 replacement host requested
00:24 restore started; 01:03 base backup complete
01:31 WAL replay reached target; 01:45 traffic enabledThe breakdown is the valuable part. Maybe provisioning dominates and warm capacity is worth paying for; maybe WAL replay dominates and recovery design must change.
Validation is part of recovery
SELECT count(*) FROM orders WHERE created_at > now() - interval '1 day';
SELECT max(id) FROM payments; SELECT count(*) FROM account_balances WHERE balance < 0;PostgreSQL starting is not success. Application invariants are success. If the wrong recovery target was chosen, a technically perfect restore can still preserve the corruption.
Field notes
- Practice both failover and failback when your architecture requires them.
- Store runbooks outside the infrastructure they describe.
- Rotate who performs drills; a single expert is a bus factor of one.
- Test timestamp assumptions and write targets in UTC.
- A drill that never finds a problem probably is not realistic enough.
Was this lesson helpful?