Lesson 5 of 9 · 26m
Database Backup Patterns: Physical, Logical, and Point-in-Time Recovery
Choose between logical exports, physical copies, continuous logs, and hybrid designs based on scale, selective restore needs, and recovery precision.
Database people learn the distinction the hard way: there is no universally best backup format. Logical dumps are portable and selective but slow at scale. Physical backups restore large systems faster but are version- and architecture-sensitive. Continuous logs create precise recovery windows but add a chain that can break silently. Senior operators choose combinations deliberately.
Logical backups trade portability for time
A logical dump serializes schema and data into database-level statements or a custom export format:
pg_dump --format=directory --jobs=4 \
--file=/backup/customerdb-$(date +%F).dir customerdbIts strengths are selective restore, cross-version migration flexibility, and human-inspectable structure. Its weaknesses appear as data grows: dump duration, restore duration, index rebuild time, and transaction pressure. A logical backup that takes nine hours to restore does not satisfy a two-hour RTO no matter how beautiful the file is.
Physical backups preserve database structure
Physical backup copies the database storage representation while coordinating consistency. PostgreSQL uses base backups plus WAL; MySQL often uses XtraBackup or filesystem snapshots; SQLite can use its online backup API. These systems restore large datasets more predictably because they avoid rebuilding every row through SQL.
pg_basebackup -D /srv/pitr/base -U replica --wal-method=stream --progressPhysical copies are coupled to database major version and sometimes CPU architecture or extension compatibility. That coupling is fine when documented and tested; it is dangerous when discovered during an incident.
PITR is a chain, not a button
Point-in-time recovery requires a valid base backup and an uninterrupted sequence of transaction logs:
base backup 12:00
WAL segment ...000A 12:01
WAL segment ...000B 12:02
WAL segment ...000C missing <-- recovery stops here
WAL segment ...000D 12:04A single missing segment can end recovery before the moment you need. Archive success must therefore be monitored as a continuity property, not a job count property.
Choose restore granularity before designing backup granularity
Ask what incidents are common. Dropped table? Accidental tenant deletion? Bad migration? Full corruption? Logical copies can make selective recovery easier, but selective restore into a live relational database is still application surgery. Foreign keys, sequences, materialized views, queues, search indexes, and object storage references may all need reconciliation.
-- Restoring rows is rarely enough; these must agree.
SELECT max(id) FROM accounts;
SELECT last_value FROM accounts_id_seq;Encryption and secrets complicate portability
If backups are encrypted with keys stored in the same system being restored, the backup exists but recovery is impossible. If keys are external, the dependency must be documented and protected. Restore instructions should name exact key identifiers and custody, not say 'ask security.'
Hybrid designs are normal
A sane production design often uses physical backups for full-service recovery, continuous logs for tight RPO, and occasional logical dumps for portability or selective recovery. That is not waste. Each format answers a different failure mode. The mistake is assuming one format answers all of them.
Field notes
- Measure restore duration, not just backup duration; index rebuilding and validation often dominate.
- Keep enough WAL around every base backup; deleting logs too early quietly invalidates PITR.
- Logical dumps of individual tables can omit sequences, ownership, privileges, constraints, and dependent objects.
Was this lesson helpful?