Sub topic 9
Marking Safe Points with Named Restore Points
Assume you already understand WAL archiving, physical base backups, and basic PostgreSQL administration. A named restore point is a label written into the WAL stream. It lets you identify a meaningful moment, such as immediately before a schema migration or application release.
Why use a named restore point?
A timestamp is useful, but it can be difficult to choose precisely. Server clocks, transaction timing, and operator delays can make a timestamp ambiguous. A restore point records a marker inside PostgreSQL's WAL sequence.
The function pg_create_restore_point(name) creates the marker and returns its WAL location, called an LSN. An LSN is a position in the WAL stream. The restore point does not create a backup by itself. You still need:
- A physical base backup from before the restore point.
- Every required WAL segment archived after that base backup.
- A recovery configuration that names the restore point.
Create the marker immediately before a risky operation:
SELECT pg_create_restore_point('before_schema_migration');Use a name that describes the event. Names such as before_release_2026_11_27 are easier to interpret than point_1.
Make the marker available for recovery
The restore point exists in the primary server's WAL. Recovery can use it only after the WAL record containing the marker has been archived and is available to the recovery process.
You can force the current WAL segment to finish so that archiving can process it sooner:
SELECT pg_switch_wal();Then check the archiver:
SELECT archived_count,
last_archived_wal,
failed_count,
last_failed_wal
FROM pg_stat_archiver;failed_count should not increase, and last_archived_wal should advance. A successful pg_switch_wal() does not guarantee that the archive copy has completed. Verify the archive location or use your backup tool's check command.
Recover to the named point
During recovery, set restore_command so PostgreSQL can fetch archived WAL. Set recovery_target_name to the marker's name:
# PostgreSQL 12 and later
restore_command = 'cp /mnt/archive/%f "%p"'
recovery_target_name = 'before_schema_migration'
recovery_target_action = 'pause'Create recovery.signal in the restored data directory before starting PostgreSQL. PostgreSQL replays WAL until it reaches the named marker. With pause, it remains in recovery so you can inspect the result. After verification, you can promote the server manually.
A named restore point is often safer than guessing a timestamp, but it has a scope limit. It marks one event in one WAL history. If the operation already committed unwanted changes before the marker, recovering to that marker will not remove those changes.
Restore-point workflow
| Operation | Purpose |
|---|---|
| `pg_create_restore_point()` | Writes a named marker into WAL |
| `pg_switch_wal()` | Completes the current WAL segment |
| `recovery_target_name` | Selects the marker where replay stops |
| `recovery_target_action` | Controls what happens after the target |
Exercise
Why should you check WAL archiving after creating a named restore point?
Show answer
The marker is useful during recovery only if the WAL containing it has been archived and can be fetched by restore_command.