Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Point-in-Time Recovery

Direct answer

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.

When to use this

Use it after accidental data changes or corruption.

First 30 seconds

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.

Operational verification

base backup → restore → replay logs to target time → open

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it after accidental data changes or corruption.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Requires continuous, complete log archiving since the base backup. Restore to a separate instance first, extract data, and avoid overwriting production blindly.

Key checks
  • SELECT * FROM pg_stat_archiver; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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

PitfallEffect
Target time in the wrong time zoneRestores an hour early or late — always include the offset
Gap in archived logsRecovery stops at the gap
Base backup newer than the targetCannot go back before the backup
Restoring over the live systemDestroys the evidence and newer data — restore to a separate host
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Terminology layer

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.

Aliases that resolve here
point-in-time recoverypoint in time recoverywal archiving pitr
Confirmation

Confirm action

Continue?