liveBook · Manning

Point-in-time recovery

As explained in PostgreSQL Mistakes and How to Avoid Them

Point-in-time recovery is a database restoration technique that replays archived transaction logs to recover a system to a selected moment or transaction.

Point-in-time recovery (PITR) restores a PostgreSQL cluster to a chosen moment or transaction after corruption, accidental changes, or malicious damage. A full backup alone restores only the state when that backup was taken; a DROP TABLE in the afternoon can otherwise lose everything written since a morning backup. section 9.2 section 9.7

PITR combines a physical base backup with continuously archived write-ahead log (WAL) files. The base backup is a binary snapshot of the entire cluster, while WAL provides a replayable record of transactions after that snapshot. Recovery replays archived WAL until the selected recovery target, stopping just before the damaging change. section 9.2

A workable PITR setup requires:

  • A base backup, commonly produced with pg_basebackup. section 9.2
  • WAL archiving configured with archive_command and retention of WAL from the start of the base backup through its completion and afterward. section 9.2
  • A recovery target time chosen before the known damage. section 9.2
  • Automation, monitoring, and restore testing rather than a manual procedure remembered by one operator. section 9.3 section 9.7

Do not try to pair a pg_dump logical backup with WAL files: PITR requires a physical base backup and its WAL history. Filesystem snapshots, RAID, and periodic full backups also leave a gap between snapshots, so they cannot reliably undo an event at an arbitrary later time. section 9.3 section 9.7

Recovering from an afternoon DROP TABLE

Suppose a verified safe base backup exists from the morning and the table is dropped in the afternoon. Restore the base backup, make the archived WAL available, and set a recovery target immediately before the drop. WAL replay can recover the cluster beyond the morning snapshot without replaying the destructive transaction. section 9.2

Figure 9.2 A sample PostgreSQL backup setup with a dedicated Barman server and geographical redundancy showing the possible transfer paths
figure

A dedicated Barman server can collect base backups and WAL, with alternative archive paths and a geographically separate copy for redundancy. section 9.3

Dedicated PostgreSQL-aware tools such as Barman and pgBackRest can schedule backups, retain recovery history, support multiple locations, and reduce the risk of ad hoc scripts. Automation is not proof of recoverability: perform full restores to verify that the backup chain works. section 9.3 section 9.7

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains base backups, WAL replay, archiving requirements, backup incompatibilities, and operational automation without detailing recovery commands.
Examples
Uses an afternoon DROP TABLE after a morning backup and a Barman-based redundant backup architecture.
What it assumes
Teaches the recovery components directly while using PostgreSQL backup and configuration utilities such as pg_basebackup and archive_command.
What you can do after
Operate/configure it by creating physical base backups, archiving WAL continuously, selecting a recovery target, and testing full restores.
How it connects
Connects PITR to write-ahead logging, base backups, WAL archiving, pg_basebackup, pg_dump, Barman, and pgBackRest.

Also explained in

Compare how 3 books explain point-in-time recovery →

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.