Sub topic 11
What Happens When the Recovery Target Is Reached
This chapter assumes that you understand physical base backups, archived WAL, restore_command, and recovery.signal. You should also know how to edit postgresql.conf and inspect PostgreSQL logs.
A recovery target tells PostgreSQL when to stop replaying WAL. The target can be a time, transaction ID, LSN, or named restore point. The recovery_target_action setting controls what PostgreSQL does immediately after it reaches that target.
The three recovery actions
| Action | Result | Typical use |
|---|---|---|
| `pause` | Stops WAL replay and keeps the server in recovery | Inspect the recovered state before opening it |
| `promote` | Ends recovery and opens the server for normal writes | Make the recovered cluster the new primary |
| `shutdown` | Stops the PostgreSQL server | Require an operator to inspect and start it deliberately |
The default action is pause. This is the safest choice when you need to verify the result before accepting writes. While paused, the server is still in recovery. It cannot operate as a normal read/write primary.
Set the action with a recovery setting:
# postgresql.conf or postgresql.auto.conf
recovery_target_time = '2026-11-27 14:30:00+00'
recovery_target_action = 'pause'You can inspect the state from a session that can connect to the recovering server:
SELECT pg_is_in_recovery();
SELECT pg_last_wal_replay_lsn();
SELECT pg_last_xact_replay_timestamp();When the target is reached, pg_is_in_recovery() returns true, and replay stops. The replay timestamp can help confirm that recovery reached the intended period. It is not a substitute for checking application data.
Pausing, inspecting, and continuing
A paused server lets you check tables, row counts, and application-specific evidence without committing new changes. For example:
SELECT pg_is_in_recovery();
SELECT count(*)
FROM orders
WHERE created_at >= timestamp '2026-11-27 14:00:00';If the result is correct and you want to finish recovery, resume WAL replay:
SELECT pg_wal_replay_resume();After replay continues, PostgreSQL follows the recovery configuration. Plan this step carefully. Once recovery is promoted, the cluster can accept writes, and those writes create a new history.
Promotion and shutdown
With recovery_target_action = 'promote', PostgreSQL stops recovery and promotes the cluster automatically:
recovery_target_action = 'promote'Promotion makes the server writable. Applications can connect only after normal authentication, networking, and service checks also succeed. Promotion is appropriate when the recovered cluster must replace a failed primary without a manual inspection stage.
With recovery_target_action = 'shutdown', PostgreSQL shuts down after reaching the target:
recovery_target_action = 'shutdown'This is useful for a controlled restore workflow. An operator can inspect the files or start PostgreSQL manually after confirming that the target was correct.
Timelines after promotion
When recovery creates a new writable history, PostgreSQL switches to a new timeline. The timeline distinguishes the recovered branch from the original primary's future WAL. PostgreSQL writes a timeline history file, such as 00000002.history.
Keep timeline history files available with the archived WAL. A later recovery may need them to identify the correct branch.
Exercise
Which recoverytargetaction should you choose when an operator must inspect recovered data before allowing writes?
Show answer
Choose pause. After inspection, resume replay or change the procedure before promoting the cluster.