liveBook · Manning

Continuous backup

As explained in PostgreSQL Mistakes and How to Avoid Them

Continuous archiving is the ongoing preservation of database transaction-log segments so changes can be replayed during recovery.

Continuous backup, also called WAL archival or continuous archiving, preserves PostgreSQL write-ahead log (WAL) files as they are produced. Combined with a base backup, those replayable transaction records enable point-in-time recovery (PITR): restore the cluster to a chosen moment after the backup rather than only to its last full-backup state. section 9.2

A base backup made with pg_basebackup is a binary-perfect snapshot of the whole database cluster. It is necessary but insufficient on its own: full backups leave a data-loss window between runs. For PITR, retain every archived WAL file from the instant the base backup starts through its completion, then onward for every recovery point that must remain available. section 9.2 section 9.7

Set up recovery as an operational chain, not as isolated backup files:

  • Configure WAL archiving with a custom archive_command in postgresql.conf. section 9.2
  • Take a full cluster backup with pg_basebackup and preserve the WAL generated during the backup itself. section 9.2
  • Restore the data directory and set recovery_target_time to the desired stopping point. section 9.2
  • Automate backups with PostgreSQL-aware software, keep a redundant copy elsewhere, and regularly perform a full restore test. section 9.7

Recover before damage

If corruption, human error, or malicious activity damages data after a base backup, restore that backup and replay archived WAL only up to the moment immediately before the damage. This avoids accepting every change made since the last full backup merely because that snapshot is the newest one available. section 9.2 section 9.7

Continuous archiving improves recovery-point capability, not necessarily service-restoration time. PITR can recover to the last committed transaction contained in the last saved WAL file, while recovery time depends on the high-availability architecture. Replication and standby nodes address redundancy and failover separately from backup recovery. section 9.5 section 9.7

Figure 9.3 A sample PostgreSQL HA setup with a cascaded replication for redundancy and backup
figure

Use the topology to distinguish backup-oriented WAL shipping from replication-based redundancy: both move WAL, but standby design also determines failover and downtime behavior. section 9.5

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains configuration, backup-time WAL retention, recovery_target_time restoration, and restore testing without detailing archive-command implementations.
Examples
Uses recovery immediately before damage and a cascaded replication topology for redundancy and backup.
What you can do after
Operate/configure WAL archiving, base backups, timed recovery, redundant backup storage, and full-restore verification.
How it connects
Connects WAL archival with point-in-time recovery, pg_basebackup, write-ahead logging, replication, RPO, and RTO.

Also explained in

Compare how 2 books explain continuous backup →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.