Use it after accidental data changes or corruption.
Point-in-Time Recovery
Point-in-time recovery restores a base backup and replays logs (WAL, binlog, transaction log) up to a chosen moment, e.g. just before a bad change.
1. Base backup available before the target time?
2. Logs complete from backup to target (SELECT * FROM pg_stat_archiver; / SHOW BINARY LOGS; / log backup chain)?
3. Restore to a new instance with the target time (recovery_target_time / STOPAT / mysqlbinlog --stop-datetime).
4. Verify data.
5. Copy back or switch over.
base backup → restore → replay logs to target time → open
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Test PITR regularly on a schedule. Confirm the archive has no gaps.
Step 2 Common failures Narrow the fault
A missing log segment stops recovery at that point. Using the wrong time zone for the target time restores to the wrong moment. Restoring over production loses changes made after the incident.
Requires continuous, complete log archiving since the base backup. Restore to a separate instance first, extract data, and avoid overwriting production blindly.
SELECT * FROM pg_stat_archiver;— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
Recovery replays log records from the base backup position and stops at the target (recovery_target_time in PostgreSQL, --stop-datetime in mysqlbinlog, STOPAT in SQL Server).
ReferenceHow it works1 section · depth on demand
How PITR works
1. Restore a base (physical) backup taken before the target time.
2. Replay archived logs (WAL / binlogs / transaction log backups) up to the target time or transaction.
3. Open the database.
# PostgreSQL (postgresql.conf + recovery.signal)
restore_command = 'cp /archive/%f %p'
recovery_target_time = '2026-11-01 09:14:00+01'
# SQL Server
RESTORE LOG Shop FROM DISK='log.trn' WITH STOPAT='2026-11-01T09:14:00', RECOVERY;
Documented example, not captured output. Log archives must be complete and continuous.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
PostgreSQL PITR in practice
1. Archive continuously: archive_mode = on and an archive_command (or archive_library) that copies each completed WAL segment to durable storage and returns non-zero on failure. Tools such as pgBackRest and Barman provide tested archiving.
2. Take base backups regularly with the same tool or pg_basebackup.
3. Restore: put the base backup in an empty data directory, configure the target, create recovery.signal, start the server.
restore_command = 'pgbackrest --stanza=shop archive-get %f "%p"'
recovery_target_time = '2026-11-27 10:41:00+01'
recovery_target_action = 'pause' # inspect before promoting
With pause, connect read-only, check that the mistaken change is not there yet, then SELECT pg_wal_replay_resume(); to promote (or adjust the target and restart).
MySQL equivalent
Restore the full backup, then replay binary logs up to just before the mistake:
mysqlbinlog --start-position=<from backup metadata> --stop-datetime="2026-11-27 10:41:00" \
binlog.000412 binlog.000413 | mysql
With GTIDs, --exclude-gtids / --include-gtids can skip exactly the bad transaction.
Pitfalls
| Pitfall | Effect |
|---|---|
| Target time in the wrong time zone | Restores an hour early or late — always include the offset |
| Gap in archived logs | Recovery stops at the gap |
| Base backup newer than the target | Cannot go back before the backup |
| Restoring over the live system | Destroys the evidence and newer data — restore to a separate host |
Common mistakes
- Missing WAL/binlog archives, breaking PITR.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.