DatabasesVol. 4 · Part IV
0 / 0

Shelves / Databases

DB·64

Durability, Backups and Recovery

Making sure data survives everything from a disk failure to an accidental DELETE to ransomware. Covers RPO and RTO, what replication does and doesn't protect against, logical versus physical backups, WAL archiving and point-in-time recovery, incremental backups, storage snapshots, the 3-2-1 rule with immutable copies, encryption and retention, corruption detection, delayed replicas, disaster-recovery strategies, and restore drills. PostgreSQL tools (pg_dump, pg_basebackup, pgBackRest, WAL-G, Barman) are compared with MySQL, managed cloud databases and NoSQL stores.

25 topics · ~21 min read · 30-question quiz
Updated Suggest a correction

Start here: the day you need your backups

Replicas are not backups

Chapter 61's replicas protect against a server dying. They do nothing against the more common disasters, because they faithfully copy every change, including the bad ones:

What goes wrong Replica helps? What helps
Server or disk failure Yes Replicas, failover
DELETE without a WHERE, a bad migration, a buggy deploy No (replicated in milliseconds) Point-in-time recovery, delayed replicas
Silent corruption (bad disk, firmware, kernel bug) Often no (corrupt pages can be replicated) Checksums, verified backups
Ransomware, a malicious insider, a deleted cloud account No Immutable, offsite, separately owned copies
A region-wide outage Only if the replica is in another region Cross-region replicas and backups

Two numbers describe what you need. RPO (recovery point objective): how much recent data you can afford to lose (zero? five minutes? a day?). RTO (recovery time objective): how long you can be down while restoring. Every backup design is a way to meet them at a cost.

Logical backups: a dump of the data

Text
$ pg_dump -Fc -f cafe.dump cafe              (while another session kept inserting)
1) pg_dump -Fc while inserts ran: 2893 ms, 14M | rows in live table after: 2200000
$ pg_restore -j 2 -d cafe_restored cafe.dump
   pg_restore -j 2: 3795 ms | rows in restored copy: 2000000 (one consistent snapshot)

pg_dump writes the schema and data as SQL or a compressed archive (-Fc). It reads everything in one transaction snapshot (chapter 57), so the dump is consistent even while the application keeps writing: the 200,000 rows inserted during the dump simply weren't in it. Logical dumps are portable (restore into a newer PostgreSQL version, or a single table), and slow to restore for large databases, because indexes must be rebuilt; and they capture only one moment: anything written after the dump is lost if you restore it.

Physical backups and point-in-time recovery

A physical backup copies the database's files (pg_basebackup, or storage snapshots). Combined with an archive of every WAL file written since, you can replay history to any moment: point-in-time recovery (PITR).

Text
$ pg_basebackup -Ft -z -X stream -c fast -D /tmp/pgbase
2) base backup: 29M compressed
   (1,000 more orders are written, then someone runs DELETE FROM orders WHERE customer < 4000 by mistake)
   … 400000 rows now, after an accidental DELETE

restore: unpack the base backup, set restore_command = 'cp /tmp/walarch/%f %p'
         and recovery_target_time = '<a moment before the DELETE>', start the server
LOG:  starting point-in-time recovery to 2026-10-29 18:11:03.855478+00
LOG:  recovery stopping before commit of transaction 808, time 2026-10-29 18:11:05.903187+00
LOG:  archive recovery complete
   restored to just before the DELETE in 4202 ms: 2001000 rows, including the 1,000 written after the backup: 1000

The restored server replayed the archived WAL from the base backup forward and stopped just before the transaction that ran the DELETE: all 2 million original orders came back, and the 1,000 orders written after the backup was taken. PITR's RPO is as small as your WAL archiving delay (seconds, with archive_timeout or streaming archivers like pgBackRest, Barman or WAL-G), which is why it's the standard backup method for production PostgreSQL.

Backups you haven't restored don't exist

Text
Bad checksums:  1                         ← pg_checksums found the corrupted page in the stopped cluster
ERROR:  invalid page in block 1000 of relation base/16407/16409
pg_basebackup: error: checksum error occurred

a base backup taken without its WAL (-X none), started on its own:
FATAL:  could not locate required checkpoint record

The lab flipped a single byte in one table page. Data checksums caught it on read and during the backup (better than silently backing up corrupt data). And a physical backup copied without the WAL needed to make it consistent couldn't even start. Both failures are invisible until someone tries to restore, which is why the only trustworthy backup strategy includes regular, automated restore drills that start the restored database and check its data.

How deep to go in durability and recovery

Volume 17 defines six mastery levels. For this chapter they look like this; the chapter aims at L3 everywhere, and its lab at L4.

Level What you can do
L1 Explain backups vs replicas, RPO and RTO, logical vs physical backups
L2 Take and restore dumps and base backups; configure WAL archiving
L3 Explain PITR, timelines, checksums, snapshots, immutability and backup tools (pgBackRest, Barman, WAL-G)
L4 Diagnose broken archives, corrupt pages, failed restores and unmet RPO/RTO
L5 Design backup and disaster-recovery strategies with drills, retention and encryption
L6 Run organisation-wide data protection with audits, ransomware resilience and recovery exercises

What you're protecting against

Threats to data

Durability at the storage level (chapter 58: WAL, fsync, checksums) protects committed transactions against crashes. Real-world data loss comes from a wider set of threats, and each needs a different defence:

Threat Example Replication helps? Backups help?
Disk or server failure A dead NVMe, a terminated VM Yes (failover) Yes (slower)
Zone or region outage A data-centre power loss Cross-zone or cross-region replicas Off-site copies
Human error DELETE FROM orders; without a WHERE, a bad migration, dropping the wrong table No: the mistake replicates instantly Yes: point-in-time recovery to just before it
Application bugs Silent data corruption over weeks No Yes, if retention goes back far enough
Software bugs or storage corruption A filesystem bug, a bad controller cache Sometimes (physical corruption may replicate) Yes, if verified
Ransomware or a malicious insider An attacker encrypts or deletes the database and its backups No Only immutable, isolated backups
Operator error on backups Backups silently failing for months — Only if restores are tested

Replication is not a backup. It's a copy of the current state, including the current mistakes. You need backups that can travel back in time, stored somewhere else, that an attacker can't delete, and that you've actually restored.

RPO and RTO

Two numbers define what "recoverable" means. Agree them with the business per system:

  • RPO (Recovery Point Objective): how much data you can afford to lose, measured in time. RPO = 5 minutes means losing at most the last 5 minutes of writes.
  • RTO (Recovery Time Objective): how long the system may be unavailable while recovering. RTO = 1 hour means service is restored within an hour.
time last recoverable point incident service restored data lost ≤ RPO downtime ≤ RTO nightly dumps: RPO ≤ 24 h · WAL archiving: minutes · sync replica: ≈ 0 restore 2 TB + replay WAL: RTO hours · promote a standby: minutes
RPO and RTO on a timeline. RPO is the gap between the last recoverable point and the incident; RTO is the time from the incident until service is restored.

Typical mechanisms and what they achieve:

Mechanism RPO RTO
Nightly logical dump only Up to 24 h Hours (restoring and rebuilding indexes on large databases can take very long)
Physical base backup + continuous WAL archiving Seconds to minutes (archive_timeout, or streaming archiving) Hours for large databases (restore + WAL replay); faster with incremental and parallel restore
Async streaming replica (same region) Seconds Minutes (promotion)
Synchronous replica ≈ 0 Minutes
Cross-region replica Seconds to minutes Minutes to an hour (DNS and application failover)
Multi-region active-active ≈ 0 (with consensus) ≈ 0 (automatic)

Lower RPO and RTO cost more money and complexity. An internal reporting database might accept RPO = 24 h and RTO = 1 day, while a payments ledger needs RPO ≈ 0 and RTO in minutes. Most production OLTP systems combine replicas for availability with PITR backups for everything replicas can't fix.

Backup methods

Logical backups

A logical backup exports data as SQL statements or a portable format:

Terminal
# PostgreSQL: custom format (compressed, parallel restore, selective restore)
$ pg_dump --format=custom --file=shop.dump --dbname="$DATABASE_URL"
$ pg_dump -Fd -j 8 -f shop_dir "$DATABASE_URL"                   # directory format: parallel dump
$ pg_restore -j 8 --no-owner --dbname=shop_restore shop_dir
$ pg_restore --list shop.dump | grep orders                 # inspect / restore single tables
$ pg_dumpall --globals-only > roles.sql                     # roles and tablespaces aren't in pg_dump

# MySQL
$ mysqldump --single-transaction --routines --triggers --set-gtid-purged=OFF shop > shop.sql   # consistent snapshot (InnoDB)
$ mysqlsh -- util dump-instance /backups/full --threads=8    # MySQL Shell: parallel dump/load
Pros Cons
Portable across major versions, architectures and even engines (with conversion) Slow for large databases: restore rebuilds every index and constraint
Selective (one table, one schema) Point in time = the dump start only: no PITR
Human-readable (plain format), good for long-term archives and migrations The dump runs a long transaction (in PostgreSQL this holds back VACUUM; on replicas, standby conflicts)
Detects some logical corruption (reading every row) —

Logical dumps are great for migrations, small databases, copying subsets, and long-term archival. For large production databases they're a supplement to physical backups, not the primary mechanism.

Physical backups and WAL archiving

A physical backup copies the database's data files (a base backup) while it's running. Since files change during the copy, the copy is inconsistent by itself, so it must be combined with the WAL generated during and after the copy to reach a consistent state. Keeping every WAL segment (continuous archiving) allows point-in-time recovery (PITR) to any moment after the base backup:

base backupSunday 02:00 WAL 0001 · 0002 · 0003 · … continuously archived DELETE FROM orders;Wed 14:03:27 restore base backup → replay WAL → stop at 14:03:26 → promote recovery_target_time = '2026-10-21 14:03:26+05:30' (or an LSN / XID)
Point-in-time recovery. A base backup plus every archived WAL segment since then lets you restore the base backup and replay WAL up to any chosen moment, such as one second before an accidental DELETE.
Terminal
# PostgreSQL built-ins
$ pg_basebackup -D /backups/base -Ft -z -X stream -P -c fast    # base backup + the WAL needed for consistency
# postgresql.conf: archive every completed WAL segment somewhere durable
#   archive_mode = on
#   archive_command = 'pgbackrest --stanza=shop archive-push %p'   (or archive_library, PG 15+)

# PostgreSQL 17: incremental base backups (uses WAL summarisation, summarize_wal = on)
$ pg_basebackup -D /backups/incr1 --incremental=/backups/base/backup_manifest
$ pg_combinebackup /backups/base /backups/incr1 -o /restore/data   # synthesise a full backup to restore

# Recovery to a point in time (PG 12+): put settings in postgresql.conf, create recovery.signal, start the server
#   restore_command = 'pgbackrest --stanza=shop archive-get %f "%p"'
#   recovery_target_time = '2026-10-21 14:03:26+05:30'
#   recovery_target_action = 'promote'           # or 'pause' to inspect before promoting

Use a dedicated backup tool rather than scripting this yourself:

Tool Highlights
pgBackRest Full, differential and incremental (block-level) backups; parallel compressed backup and restore; S3/GCS/Azure repositories; encryption; checksum verification; backup from standby; asynchronous WAL archiving; retention policies. The de facto standard for self-managed PostgreSQL
WAL-G (Go) Cloud-native backup and WAL archiving for PostgreSQL, MySQL/MariaDB, SQL Server and MongoDB; delta backups; compression and encryption
Barman (EDB) A backup server managing multiple PostgreSQL servers, with streaming archiving and a catalogue
CloudNativePG / Crunchy PGO (Kubernetes) Operators with built-in backups (Barman Cloud or pgBackRest), PITR and replica clusters
MySQL: Percona XtraBackup, MySQL Enterprise Backup, the Clone plugin; binlog archiving for PITR (mysqlbinlog --stop-datetime) Hot physical backups of InnoDB plus binary logs
SQL Server: full, differential and log backups (the full recovery model) The classic three-tier scheme with STOPAT restore
Oracle: RMAN with archived redo logs, Flashback Database Mature enterprise tooling

Storage snapshots

Cloud volumes (EBS, Persistent Disk, Azure Managed Disks), SANs and filesystems (ZFS, LVM, Btrfs) can take block-level snapshots almost instantly:

  • They're crash-consistent: equivalent to pulling the power plug. The database recovers from its WAL on startup, which is fine if the WAL and data are on the same volume (or snapshotted atomically as a group). Multi-volume setups need consistency groups, or pg_backup_start()/pg_backup_stop() around the snapshot.
  • Snapshots are fast to take and to restore (lazily hydrated volumes), which makes them good for low RTO.
  • They're typically in the same account and region: copy them cross-region and cross-account, and lock them, for real protection.
  • Combine them with WAL archiving to get PITR between snapshots.

Managed databases (RDS, Aurora, Cloud SQL, Azure Database, AlloyDB, Neon, MongoDB Atlas, DynamoDB) provide automated backups with PITR (typically 1–35 days of retention) plus manual snapshots. You still need to:

  • set retention to match requirements;
  • copy backups to another region or account (AWS Backup cross-account vaults, cross-region snapshot copies);
  • enable deletion protection;
  • test restores: a managed restore creates a new instance, and your runbook must cover repointing applications.

DynamoDB has PITR (up to 35 days) and on-demand backups. Neon and other branching databases make "restore to a point in time" as cheap as creating a branch.

Protecting the backups

The 3-2-1 rule, immutability and encryption

The classic 3-2-1 rule: at least 3 copies of the data, on 2 different media or storage systems, with 1 off-site. The ransomware-era extension is 3-2-1-1-0: plus 1 immutable or air-gapped copy, and 0 errors in verified restores.

  • Immutability: object storage with WORM locks (S3 Object Lock in compliance mode, Azure immutable blob storage, GCS bucket lock), backup vault locks (AWS Backup Vault Lock), or offline copies. Attackers who compromise production credentials routinely delete backups first. Backups must be unreachable with production credentials: separate accounts, separate credentials, write-only access from production, and deletion requiring a different identity.
  • Encryption at rest (pgBackRest repo-cipher-type, KMS-encrypted buckets) and in transit. Back up the keys separately, since losing the key loses the backups. Rotate keys with a plan.
  • Retention: keep enough history to detect slow-burning corruption or bugs (weeks to months), and balance it against storage cost and privacy law. GDPR erasure requests interact with backups, so document how deleted personal data ages out of backups.
  • Monitoring: alert when a backup or WAL archiving fails or falls behind. archive_command failures make pg_wal fill the disk, and they mean no PITR coverage. Monitor pg_stat_archiver (failed_count, last_archived_time).

Corruption detection

Backups of corrupted data are corrupted backups, so detect corruption early:

  • Data checksums (initdb --data-checksums, on by default since PostgreSQL 18) detect corrupted pages on read. InnoDB has page checksums by default.
  • amcheck (bt_index_check, heapallindexed, verify_heapam) and the pg_amcheck command verify B-tree and heap invariants.
  • Backup verification: pgBackRest verifies checksums during backup, and pg_verifybackup checks backup manifests (PG 13+).
  • Logical dumps read every row and fail on some corruption, which makes a periodic dump a useful extra check.
  • Monitor storage-level errors (dmesg, SMART, cloud volume health) and any invalid page or checksum failure messages in database logs.

Delayed replicas for human error

A delayed standby applies WAL with a deliberate lag. If someone drops a table, you have that much time to stop replay and extract the data, which is much faster than a full PITR from backups:

Text
# postgresql.conf on a delayed standby
recovery_min_apply_delay = '4h'
# After an accident at 14:03: pause replay (SELECT pg_wal_replay_pause();), set recovery_target_time = '…14:03:26',
# resume until it stops there, then copy out the lost data with pg_dump -t or COPY.

MySQL has CHANGE REPLICATION SOURCE TO SOURCE_DELAY = 14400. Delayed replicas complement backups. They don't replace them.

Also reduce the chance of human error in the first place: require WHERE clauses (MySQL sql_safe_updates; review tooling), run migrations through CI with review, don't give humans write access to production databases by default (break-glass procedures), and use soft deletes or history tables for critical entities where business rules allow.

Recovering

Disaster recovery strategies

For whole-region or whole-environment loss, standard cloud DR strategies (AWS's Well-Architected framework names them, but they're universal) trade cost against RPO and RTO:

Strategy Description RPO / RTO Cost
Backup & restore Backups copied to another region; infrastructure rebuilt there when needed (infrastructure as code, Part VIII) Hours / hours to a day Lowest
Pilot light Core data replicated continuously to the DR region (a database replica); other components off or minimal Minutes / tens of minutes to hours Low
Warm standby A scaled-down but fully working copy of the whole stack running in the DR region Seconds to minutes / minutes Medium
Multi-site active-active Both regions serve traffic; data replicated (multi-region databases, conflict handling) ≈ 0 / ≈ 0 Highest; hardest (consistency, Vol. 5)

Whatever the strategy, DR depends on more than the database: DNS and traffic failover, secrets and keys available in the DR region, configuration, container images replicated, third-party allow-lists (IP addresses), and people who know the runbook.

Restore drills

A backup you haven't restored is a hope, not a backup. History is full of companies whose backups turned out to be empty, corrupted, incomplete (missing WAL, missing roles, missing keys) or too slow to restore within any acceptable RTO. A restore drill programme:

  1. Automate restore verification: a scheduled job restores the latest backup (with PITR to a recent time) into an isolated environment, starts the database, runs pg_amcheck, checks row counts and checksums against expectations, runs application smoke tests, and reports the restore duration. That duration is your measured RTO.
  2. Run game days: practise realistic scenarios with the on-call team (a dropped table: recover just that table; region loss: fail over to DR; ransomware: restore from the immutable copy with fresh credentials). Time them, write down every surprise, and fix the runbook.
  3. Keep runbooks current: exact commands, where backups and keys are, who has access, how to repoint applications, how to communicate (Vol. 6 covers incident management).
  4. Cover the whole system: databases, object storage (versioning plus replication), message brokers (Kafka topics are often treated as rebuildable, but are they?), search indexes (rebuildable from the source of truth), caches (rebuildable), secrets, configuration and infrastructure state.
  5. Review RPO and RTO against what drills actually achieve, and report the gaps to stakeholders.
Terminal
# A minimal nightly restore check for pgBackRest (run in an isolated environment)
$ pgbackrest --stanza=shop --delta --type=time --target="$(date -u -d '-1 hour' '+%F %T+00')" \
             --target-action=promote restore
$ pg_ctl -D /var/lib/postgresql/restore start
$ pg_amcheck --all --heapallindexed
$ psql -c "SELECT count(*) FROM orders WHERE created_at > now() - interval '1 day';"   # sanity: recent data present
$ ./smoke-tests.sh --db=restore && echo "restore OK in ${SECONDS}s" | report-metric restore_duration_seconds

Backups across data stores

Store Backup approach PITR
PostgreSQL pgBackRest / WAL-G / Barman, pg_dump for logical WAL archiving
MySQL / MariaDB XtraBackup, MySQL Shell dumps, Clone plugin Binlog replay
SQL Server Full + differential + log backups Log backups (STOPAT)
Oracle RMAN Archived redo, Flashback
MongoDB mongodump (logical), filesystem snapshots, Atlas cloud backups, Percona Backup for MongoDB Oplog-based PITR
Cassandra / Scylla nodetool snapshot per node (hard links to SSTables) + incremental backups + commitlog archiving; Medusa (Cassandra) and Scylla Manager orchestrate them Commitlog replay (limited), point-in-time via tooling
Redis RDB snapshots and AOF files copied off-host AOF to the last fsync
DynamoDB On-demand backups, PITR (35 days), export to S3 Yes (managed)
Elasticsearch / OpenSearch Snapshot API to object storage (incremental at segment level) No (rebuild from the source of truth, or restore a snapshot)
Kafka Replication is the primary durability; MirrorMaker 2 or Cluster Linking for DR; tiered storage Retention-based replay
SQLite .backup / VACUUM INTO, Litestream (continuous WAL replication to object storage) Litestream restores to points in time

The principle across all of them: identify the system of record for each piece of data, back it up with PITR and immutability, test restores, and make sure everything else is derived and rebuildable from it, with that rebuild practised too.

Lab: backing up, breaking and restoring

A separate PostgreSQL 16 cluster initialised with --data-checksums, wal_level = replica, archive_mode = on and archive_command = 'test ! -f /tmp/walarch/%f && cp %p /tmp/walarch/%f' (a local directory standing in for object storage), holding a 150 MB database of 2 million orders.

Experiment 1: a logical backup under load

Text
pg_dump -Fc while inserts ran: 2893 ms, 14M | rows in live table after: 2200000
pg_restore -j 2: 3795 ms | rows in restored copy: 2000000 (one consistent snapshot) | id range has no gaps: t

The custom-format dump was a tenth of the database's size (compressed data, no indexes) and taken without stopping writes. It captured exactly the rows committed when it started. Restoring took longer than dumping, because every index and constraint had to be rebuilt; for large databases, restores of logical dumps take hours, which usually rules them out as the primary disaster-recovery method. They remain the right tool for moving data between versions or systems, extracting single tables, and as a second, independent copy.

Experiment 2: point-in-time recovery from a mistake

The sequence: base backup → 1,000 new orders → note the time → an accidental DELETE of 80% of orders → restore the base backup on a new port with recovery_target_time set to the noted time.

Text
base backup: 29M compressed
… 400000 rows now, after an accidental DELETE
LOG:  starting point-in-time recovery to 2026-10-29 18:11:03.855478+00
LOG:  recovery stopping before commit of transaction 808, time 2026-10-29 18:11:05.903187+00
LOG:  redo done at 0/56B786C8 system usage: CPU: user: 0.52 s, system: 0.16 s, elapsed: 2.64 s
LOG:  selected new timeline ID: 2
LOG:  archive recovery complete
restored to just before the DELETE in 4202 ms: 2001000 rows, including the 1,000 written after the backup: 1000

Recovery replayed archived WAL and stopped immediately before the deleting transaction's commit, then started a new timeline (2), so the recovered history can't be confused with the original one. In real incidents the hard part is the timestamp: you rarely know exactly when the mistake happened. Restore to a scratch server first, inspect, and copy back only the missing rows if the live database has since received valid new writes; recovery_target_xid or recovery_target_lsn (from pg_waldump or the logs) are more precise than times. While building this experiment, the first attempt queried the restored server while it was still replaying (hot standby allows read-only queries during recovery) and got a count from mid-recovery: always wait until pg_is_in_recovery() is false.

Experiment 3: one flipped byte

One byte in page 1,000 of the orders table file was inverted while the server was stopped:

Text
$ pg_checksums --check -D /tmp/pgtest
Blocks scanned:  22002
Bad checksums:  1

SELECT count(*), sum(total_paise) FROM orders;
WARNING:  page verification failed, calculated checksum 43208 but expected 58973
ERROR:  invalid page in block 1000 of relation base/16407/16409

$ pg_basebackup …
pg_basebackup: error: checksum error occurred

With checksums, corruption is detected on the first read of the damaged page, and pg_basebackup refused to produce a backup containing it. Without checksums (the default before PostgreSQL 18 unless enabled at initdb), PostgreSQL would have read the garbage, possibly returned wrong totals, and backed it up faithfully, overwriting good backups as retention rotated. Enable checksums, run pg_amcheck for index and heap consistency periodically, and keep backups long enough to reach back before corruption you discover late. Recovery here means restoring the damaged table from a backup (PITR to a scratch server, then copy), not "repairing" the page.

Experiment 4: a backup that can't restore

A base backup taken with -X none (no WAL included), started on its own without access to the archive:

Text
FATAL:  could not locate required checkpoint record

A physical copy of a running database is only consistent together with the WAL generated while it was being taken. This backup looked complete (all the data files were there) and was useless. Similar silent failures: an archive_command that's been failing for weeks (watch pg_stat_archiver.failed_count and last_failed_wal), backups encrypted with a key nobody can find, snapshots taken without pg_backup_start, or restores that need a tool version nobody has. Only an automated, regular restore drill (restore, start, run checks, record the time as your measured RTO) catches them.

Try it yourself

  1. Install pgBackRest or WAL-G, configure full and incremental backups to a local "repository", and time a restore of the 150 MB database. How does it compare with experiment 1's pg_restore?
  2. Recover experiment 2 using recovery_target_xid instead of a timestamp. How do you find the xid of the bad transaction?
  3. Set up a replica with recovery_min_apply_delay = '1h' and use it to undo a mistake without PITR.
  4. Break the archive_command (point it at a missing directory), generate traffic, and find the failure in pg_stat_archiver before any restore needs that WAL.

Revision sheet: durability, backups and recovery

Key ideas

  • Threats: hardware failure, human error, software bugs, corruption, malicious action (ransomware, insiders), regional disasters; replicas cover only the first.
  • Objectives: RPO (data loss tolerance) and RTO (downtime tolerance), per dataset; tested, not assumed.
  • Logical backups: pg_dump/pg_dumpall, formats (-Fc, -Fd parallel), consistent snapshot, portable, slow restore; good for migrations and single objects.
  • Physical backups: pg_basebackup, pgBackRest, Barman, WAL-G; full, differential and incremental (PostgreSQL 17 native incremental); WAL archiving; PITR with recovery targets and timelines.
  • Snapshots: storage/EBS snapshots with pg_backup_start/pg_backup_stop or crash-consistent with WAL on the same volume.
  • Protection of backups: 3-2-1 (three copies, two media, one offsite), immutability (object lock, WORM), encryption with managed keys, separate accounts and credentials.
  • Integrity: data checksums (default from PostgreSQL 18), pg_amcheck, pg_checksums, backup verification (pgbackrest verify, pg_verifybackup).
  • Recovery practice: delayed replicas, scratch restores, runbooks, measured restore drills, retention long enough to predate late-discovered corruption.
  • Other stores: MySQL (binlog PITR, XtraBackup), MongoDB (oplog), Redis (RDB/AOF), managed-service snapshots and PITR windows.

Numbers to remember

  • Lab: a 150 MB database dumped in 2.9 s to 14 MB and restored in 3.8 s; PITR restored 2,001,000 rows to just before a mistaken DELETE in 4.2 s; one flipped byte was caught by checksums on read and during backup; a base backup without WAL wouldn't start.

Pitfalls

  • Treating replicas, RAID or snapshots on the same account as backups.
  • Never restoring; unmonitored archive failures; backups without the WAL they need.
  • Backups in the same blast radius as production (same account, same credentials, same region).
  • Checksums off; retention shorter than the time to discover corruption.
  • Querying a restoring server mid-recovery; recovering over the live database instead of to a scratch copy.

Glossary

  • PITR: point-in-time recovery by replaying archived WAL onto a base backup.
  • Base backup: a physical copy of the data directory plus the WAL needed to make it consistent.
  • Timeline: a branch of WAL history created by recovery or promotion.
  • WAL archiving: copying completed WAL segments to durable storage.
  • Immutable backup: a copy that can't be modified or deleted for a retention period.
  • Restore drill: a regular, measured test of restoring and validating a backup.