Video in progress

How do you build a backup strategy for Postgres, and why isn't pg_dump enough on its own?

pg_dump gives a logical snapshot: good for small databases and for migration, but it restores only to the moment of the dump and is slow on a big database. A serious system needs a physical base backup and a continuous WAL archive, which is what gives you restore to any second (PITR). And if you don't restore a backup regularly, you can't trust it.

📖 Answer

The types of backup:

pg_dump Physical + WAL (pgBackRest, WAL-G, Barman)
Restore point only the dump time any time (PITR)
Time on a 1 TB database hours to take, even longer to restore (indexes are rebuilt) faster, with incremental/differential
Cross-version migration yes no (same major version)
Restoring a single table easy hard (restore the whole cluster, then copy it over)

A replica is not a backup: a DROP TABLE or a bad UPDATE reaches the replica instantly too. A delayed replica (recovery_min_apply_delay = '4h') helps partially, but doesn't fully replace a backup.

How PITR works:

base backup (Sunday 02:00) + WAL archive (continuous)
incident: on Wednesday at 14:32 someone ran a DELETE
restore: base backup + replay the WAL up to recovery_target_time = '... 14:31:00'

The requirements I set:

  • the backup is somewhere else (another region or object storage), encrypted, with separate access rights, so that even if ransomware takes over the main server it can't delete the backup;
  • an alert if archive_command fails, otherwise pg_wal fills up and the primary stops;
  • retention: for example a 14-day PITR window plus monthly long-term copies;
  • an automated restore test: every week, restore the backup onto a separate server, run the application's smoke test and measure the time. The RTO is learned from exactly this measurement.

I keep pg_dump alongside it too, for quickly bringing back a single table or for copying to a dev environment. But the main protection is the physical backup and the WAL.