PostgreSQL PITR: recover to a chosen point in time and verify it safely
PostgreSQL point-in-time recovery (PITR) restores a physical base backup, then replays the continuous sequence of write-ahead log (WAL) files created after it until the chosen point. A base backup alone cannot restore changes made afterward, and WAL alone lacks the full data files needed to start recovery, so both pieces and an unbroken archive are required. PITR recovers a whole database cluster; validate the target and result on an isolated copy before redirecting production traffic.
This article follows PostgreSQL 19 documentation published on November 19, 2026. PITR does not apply to logical pg_dump archives. Managed database services may have their own recovery interfaces and constraints, so follow the provider’s procedure when applicable.
What does PITR replay?
WAL records changes to database files in order. As in crash recovery, PostgreSQL starts from the files in a physical base backup and replays the needed WAL to reach a consistent state. Replaying through the latest available WAL recovers as close to the current state as possible; stopping at a target produces a consistent earlier state. This can provide many recovery points without copying a large database in full each time, but it is more complex than a logical dump because the archive chain must be operated and verified. PostgreSQL 19: Continuous Archiving and PITR
A PITR plan has three parts:
**Physical base backup:** the starting files for the cluster. PostgreSQL documents `pg_basebackup` as the straightforward method.
**Continuous WAL archive:** every segment needed from the start of the base backup through the desired recovery point, with no gaps.
**A recovery target and validation plan:** specify where replay stops, inspect the recovered state, then decide whether to put it into service.
pg_dump and pg_dumpall are logical exports and do not contain the physical information needed for WAL replay. PITR also does not rewind just one table. To recover a table’s earlier contents, restore a separate cluster to the desired point, extract the data, and apply it to the production database through a separate controlled procedure. PostgreSQL 19: Continuous Archiving and PITR
What must be ready before recovery?
If archiving has not been configured until after an incident, required WAL may already be gone. PostgreSQL archives completed WAL segments and recommends testing the archive process before taking the first base backup. PostgreSQL 19 documents wal_level=replica or higher, archive_mode=on, and an archive_command or archive_library. Changing wal_level requires a server restart, so plan for that operational impact. PostgreSQL 19: WAL settings · Continuous archiving setup
The archive command must report success only after a segment is safely stored. PostgreSQL may recycle a segment after a successful response. On failure it retries, but prolonged lag can grow pg_wal until the disk fills. Alert on archive failures, lag, and free space. WAL contains effectively the database’s contents, so restrict access to the archive. Configuration files such as postgresql.conf and pg_hba.conf are not recreated by WAL replay; protect them separately. PostgreSQL 19: WAL archiving
A missing WAL segment can stop recovery at that gap. Retention is therefore a recoverability policy, not just a storage optimization. Keep the base backup, its history and tablespace data, and every WAL segment needed through the target. The right retention window depends on write volume, recovery objectives, and storage capacity.
How do you choose the recovery target?
PostgreSQL can stop at a timestamp, a named restore point, an LSN, or a transaction ID. For recovery_target_time, use a timestamp with a time zone and confirm that clocks and incident records use the same reference. A named point must have been created earlier with pg_create_restore_point(). A transaction ID may be difficult to identify accurately. Set only one target selector for a recovery. PostgreSQL 19: Recovery Target Settings
recovery_target_inclusive controls whether a transaction exactly at the target is included. If the goal is “just before the deletion,” do not guess a timestamp without checking audit and application logs and transaction boundaries. Multiple changes within a second may not be distinguishable by wall-clock time alone. The target must be later than the end of the base backup; to recover to a time during that backup, use an earlier base backup. PostgreSQL 19: PITR caveats · Recovery target options
Also choose what the server should do when the target is reached: recovery_target_action can pause, promote the recovered server to normal writable operation, or shut it down. When validation matters, pause recovery and inspect the isolated copy before promotion. PostgreSQL 19: Recovery Target Settings
What is a safe isolated recovery sequence?
Adapt this documented sequence to your storage, users, permissions, and tablespace layout. These are instructional steps, not a recovery that was executed for this article.
**Fix the target.** Record the incident time, desired state, and acceptable data loss. Identify which WAL range is required. If uncertain, preserve the restore copy so you can try nearby targets.
**Isolate the recovery server.** Use a separate data directory and, if possible, host. Block application writes and ordinary users. Preserve the original files and WAL so you can retry if needed.
**Restore the base backup.** With PostgreSQL stopped, restore files into the recovery data directory with the database system user as owner. Check external tablespaces and symbolic links. Destructive file cleanup belongs only on the new restore target, never on the production source.
**Set recovery configuration.** Configure `restore_command`, choose one target, and create `recovery.signal` in the data directory. For a staging restore whose archive path really is `/mnt/server/archivedir`, a Unix-shaped example is:
restore_command = 'cp "/mnt/server/archivedir/%f" "%p"'
recovery_target_time = '2026-11-23 10:30:00+09'
recovery_target_inclusive = false
recovery_target_action = 'pause'These values illustrate syntax; they are not production settings. Verify %f and %p substitution, file permissions, event time, and time zone. restore_command must return failure when a requested file is absent, which can be a normal part of WAL searching. recovery.signal starts targeted recovery; if standby.signal also exists, standby mode takes precedence. PostgreSQL 19: Archive Recovery Settings
**Start the server and inspect logs.** Confirm that WAL is applied in order and the target is reached. Recovery can resume after an external interruption, but corrupt or missing WAL can halt it. Retry from the preserved copy with an adjusted target if needed.
**Validate before opening access.** Check key rows around the target, business invariants, schema, roles and permissions, extensions, sequences, and application read paths. Compare with incident logs to confirm the recovered time.
**Decide on promotion and cutover separately.** After validation, finish recovery if it is paused. Then deliberately redirect connection strings, DNS, or load balancers. Decide when the original can be reopened and how to prevent both copies accepting writes.
PostgreSQL recommends inspecting recovered contents and allowing users to connect only after success is confirmed. PITR changes the state of a whole cluster; do not assume it rewound only the affected table. PostgreSQL 19: Recovering Using a Continuous Archive Backup
Why does the new timeline matter?
When recovery finishes and writes resume, PostgreSQL creates a new WAL history from that point and marks it as a new timeline. The original later WAL is not necessarily erased, but subsequent recovery must distinguish the original history from the new branch. If you test multiple targets, preserve each recovery artifact and timeline, and do not delete old WAL from a shared archive prematurely. PostgreSQL 19: Timelines
PITR is also different from a high-availability standby. A standby normally keeps applying incoming WAL to follow the latest primary, while targeted recovery intentionally stops at a selected target. They use WAL for different purposes and use different signal files and post-recovery behavior. A failover plan is not a PITR drill, and an unvalidated PITR copy is not automatically a replacement production server. PostgreSQL 19: Recovery Modes and Targets
What should you monitor and troubleshoot?
Monitor archive lag, the age of the oldest unarchived segment, storage headroom, and whether each retained base backup has the WAL it needs. If storage fills, PostgreSQL cannot mark segments archived; retries can accumulate files under pg_wal and fill its filesystem. Check that the archive program’s success code is accurate, it does not overwrite existing files, access is restricted, and restore commands still work. PostgreSQL 19: WAL Archive Operations
**Recovery stops early:** inspect logs for missing or unreadable WAL, a wrong `restore_command`, or permissions. Retry from the preserved copy.
**Wrong data point:** recheck time zone, clock synchronization, inclusive behavior, and incident records. Compare nearby targets on separate copies if the exact boundary is unclear.
**Archive grows unexpectedly:** do not delete old WAL blindly. First calculate what every retained base backup and recovery target still needs.
**Server starts but the app fails:** check ownership, permissions, extensions, sequences, statistics, external configuration files, and which copy the application connects to.
Success means evidence that the desired data state was restored and the service uses the correct copy, not merely that the server started. Record recovery time, operator, checks, and remaining risks so the next drill can improve the runbook.
Scope and sources
This article follows official PostgreSQL 19 documentation reviewed on November 23, 2026. Paths and commands are POSIX-style examples, not guaranteed-safe commands for a particular cloud or production environment. No database recovery was performed or timed. For managed databases, follow the provider’s PITR instructions and recovery simulation tools.
[PostgreSQL 19: Continuous Archiving and PITR](https://www.postgresql.org/docs/19/continuous-archiving.html)
[PostgreSQL 19: WAL Settings and Recovery Targets](https://www.postgresql.org/docs/19/runtime-config-wal.html)
[PostgreSQL 19: `pg_basebackup`](https://www.postgresql.org/docs/19/app-pgbasebackup.html)
[PostgreSQL 19: Backup and Restore Overview](https://www.postgresql.org/docs/19/backup.html)