In PostgreSQL 18, which signal file and which settings make a restored base backup replay archived WAL only up to a chosen timestamp?
answer
- an empty file, not a config file
- restore_command is the one requirement
- one recovery_target_* setting only
- a leftover recovery.conf blocks startup
basics
~10 sCreate an empty recovery.signal in the restored data directory, set restore_command and recovery_target_time in postgresql.conf, and start the server. Since PostgreSQL 12 there is no recovery.conf; a leftover one stops the server starting.
solid answer
~40 sRestore the base backup into an empty data directory and clear the stale files from its `pg_wal`. In `postgresql.conf` set `restore_command`, which copies archived file `%f` to path `%p` and must exit non-zero when the file is not in the archive, and exactly one target, such as `recovery_target_time = '2026-10-02 14:31:00+00'`. Then create an empty `recovery.signal` in the data directory and start the server: it enters targeted recovery, replays archived WAL, and stops at the target, by default pausing there. `standby.signal` would instead make it a standby that keeps following new WAL, and wins if both files exist. PostgreSQL 12 removed `recovery.conf`; on 18 a server with that file will not start. The target must lie after the end of the base backup.
code
bash · 5 lines# base backup already restored into the empty data directory
PGDATA=/var/lib/postgresql/18/main
find "$PGDATA/pg_wal" -maxdepth 1 -type f -delete
touch "$PGDATA/recovery.signal"
pg_ctl -D "$PGDATA" startgo deeper
Recall recovery.signal, restore_command and a single recovery_target_* setting, and that recovery.conf no longer exists.
Explain the procedure end to end: empty data directory, stale pg_wal cleared, settings, signal file, start, and what the server does with recovery.signal when recovery ends.
Show you know restore_command's edge cases, the one-target rule, the timestamp format, and why a target inside the backup window cannot work.
Frame the recovery as a rehearsed runbook with owners and timings, and decide where the recovered copy runs before production is touched.
## From recovery.conf to recovery.signal Up to PostgreSQL 11, recovery was driven by a separate `recovery.conf` file. PostgreSQL 12 removed it: archive recovery, standby mode and point-in-time recovery are configured with ordinary server parameters in `postgresql.conf`, and the **mode** is chosen by an empty **signal file** in the data directory. A PostgreSQL 18 server will not start if a `recovery.conf` is present. | Signal file | Mode | When replay stops | |---|---|---| | `recovery.signal` | targeted recovery | at the recovery target, or when archived WAL runs out | | `standby.signal` | standby | not at the end of the archive: it keeps fetching WAL from the archive or a primary | | both present | standby wins | as for a standby | | neither | normal start | after crash recovery of local WAL | ## The restore, step by step Take a legal-documents database: on 2 October 2026 at 14:32 UTC a maintenance script ran a `DELETE` on `legal_documents` without its `WHERE` clause. There is a base backup from 02:00 and an intact WAL archive. 1. Stop the server if it is still running, and keep a copy of its `pg_wal/`: it may hold segments that were never archived. 2. Restore the base backup into an empty data directory with the right ownership. An incremental chain is first rebuilt with `pg_combinebackup`, which is covered with base backups. 3. Remove the files in the restored `pg_wal/`; they are stale copies taken with the backup. 4. In `postgresql.conf`, set `restore_command` and one recovery target, here `recovery_target_time = '2026-10-02 14:31:00+00'`. 5. Create an empty `recovery.signal`, and consider tightening `pg_hba.conf` so applications cannot connect yet. 6. Start the server. It replays from the backup's starting point, fetching each archived segment through `restore_command`, and stops at the target. 7. Inspect the data; what happens at the target is set by `recovery_target_action`, whose default is `pause`. When recovery finally ends and the server opens for writes, it deletes `recovery.signal` so it cannot re-enter recovery by accident, and it starts a new timeline. ## restore_command: the archive contract in reverse `restore_command` is the one setting archive recovery cannot do without. - `%f` is the file name to fetch and `%p` the destination path, relative to the data directory. The base name of `%p` differs from `%f`, so do not use one in place of the other. - It **will** be asked for files the archive does not have: the segment after the last one archived, and timeline history files such as `00000002.history`. It must exit non-zero then. That is the normal way to say *not here*, and recovery falls back to `pg_wal/` or ends. - If the command is killed by a signal other than `SIGTERM`, or the shell fails (*command not found*), recovery aborts and the server does not start. - Segments available in the archive are preferred over files in `pg_wal/`; files in `pg_wal/` are used only when the archive lacks them. - `restore_command` can be changed with a reload; the recovery target settings are read only at server start. ## The recovery target settings At most one of these may be set; configuring a second one raises an error. | Setting | Recovery stops | Where the value comes from | |---|---|---| | `recovery_target_time` | at that commit time | the incident timeline | | `recovery_target_xid` | at that transaction's commit | the server log or `pg_waldump` | | `recovery_target_lsn` | at that WAL position | `pg_waldump`, or a saved `pg_current_wal_lsn()` | | `recovery_target_name` | at a marker from `pg_create_restore_point()` | created before risky work | | `recovery_target = 'immediate'` | at the backup's consistent point | no value needed | With the default `recovery_target_inclusive = on`, a transaction committing at exactly the target time, xid or LSN is kept. Write `recovery_target_time` in `timestamptz` format with a numeric UTC offset or a full zone name such as `Europe/Helsinki`; zone abbreviations are rejected unless `timezone_abbreviations` was set earlier in the file. The target must lie **after the end of the base backup**. If replay reaches the target before the restored backup is consistent, recovery fails with *requested recovery stop point is before consistent recovery point*, and you need an older base backup.
- Why does a healthy PostgreSQL point-in-time recovery log failures to fetch a .history file and, at the end, a WAL segment?`restore_command` is asked for files that may not exist: timeline history files such as `00000002.history` while recovery looks for newer timelines, and the segment after the last one archived. Exiting non-zero there is the normal way to say the file is not in the archive; recovery then tries `pg_wal` or ends. Only a signal kill or a shell error such as command not found aborts recovery.
- What happens in PostgreSQL if the recovery target lies inside the period while the base backup was being taken?Recovery cannot stop before the restored backup is consistent, which is the point where the backup finished. The server fails with requested recovery stop point is before consistent recovery point. Restore the previous base backup instead and roll forward from it to the target.
- On PostgreSQL 18 you put the recovery settings in recovery.conf in the data directory
- standby.signal and recovery.signal are two names for the same recovery mode
- Set recovery_target_time and recovery_target_xid together to be extra safe
- restore_command should exit zero when the requested file is missing
- Keep the pg_wal contents that came with the base backup; they speed recovery up
Assumes PostgreSQL 18; since PostgreSQL 12 recovery is configured in postgresql.conf plus a signal file, and recovery.conf prevents startup.