backup-and-recoverylisted
Install: claude install-skill matejformanek/postgres-claude
# backup-and-recovery — base backup + WAL archiving + PITR
PG's backup strategy is TWO PARTS:
1. **Base backup** — a full copy of the data directory at a point in time. Made by `pg_basebackup` (client) which drives the server's basebackup code, OR by filesystem-level tools + `pg_backup_start` / `pg_backup_stop`.
2. **WAL archive** — every WAL segment shipped to secondary storage as it fills. Enables replay from the base backup to any later LSN.
Together: recovery starts from base backup + replays WAL up to the desired point (crash-recovery-latest, specific LSN, specific time, specific named restore point).
## The file map
### Backup (primary side)
| File | Role |
|---|---|
| `src/backend/backup/basebackup.c` | Server-side base-backup driver — walks the data directory, streams files to client, coordinates checkpoint. |
| `src/backend/backup/basebackup_copy.c` | Copy protocol integration. |
| `src/backend/backup/basebackup_gzip.c` / `_lz4.c` / `_zstd.c` | On-the-fly compression variants. |
| `src/backend/backup/basebackup_target.c` | Where to write — client stream vs server-side path. |
| `src/backend/backup/basebackup_incremental.c` | (PG 17+) Incremental backup driver — uses WAL summary files. |
| `src/backend/backup/basebackup_progress.c` | Progress reporting via pgstat_progress_backup. |
| `src/backend/backup/basebackup_server.c` | Server-side backup target — writes to a filesystem path directly, not client-stream. |
| `src/backend/postmaster/pgarch.c` | The archiver