Skip to main content
← CONCEPTS / DATABASES & STORAGE ENGINES
An end-to-end domain learning journey

Point-in-Time
Recovery.

Point-in-time recovery (PITR) pairs periodic physical base backups with continuous transaction log archiving (such as PostgreSQL WAL or MySQL binlogs) so you can rewind a database to any exact second, transaction ID, or log sequence number before a destructive event.
Start the journey7 sections· Last modified Oct 23, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When concurrent writes contend on shared state, snapshots alone lose everything written since the last backup; PITR bounds data loss to your log-shipping interval by replaying committed changes up to the exact instant before corruption.

TL;DR30-second simplified summary
▾

Core Mechanics: Every ACID database writes state changes to an append-only transaction log (Write-Ahead Log in PostgreSQL, Redo/Binlog in MySQL) before dirty pages hit data files.

Visual & Structural Flow: Depicts PITR Restoration Architecture (Base Snapshot + WAL Stream) (Base Backup (02:00) -> S3 WAL Archive -> Target Stop (11:14:07) -> Timeline 00000002); Non-Destructive PITR Replay & Verification Sequence (SRE / Operator -> S3 (pgBackRest) -> Recovery Cluster -> Live Primary).

Trade-Offs & Production: Balance RPO, RTO on multi-terabyte databases, and operational complexity. A 400 GB Postgres 16 cluster takes a pgBackRest full backup at 02:00 UTC and ships WALs to S3.

Failure Modes & Application: Explore WAL internals, PostgreSQL maintenance, and multi-region disaster recovery.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Database Indexing: B-Trees vs LSM-Trees
B-Trees organize sorted keys into fixed-size mutable pages optimized for fast, predictable point and range reads, whereas LSM-Trees buffer writes in memory and flush immutable sorted runs to disk for high write throughput.
Full walkthrough · 7 stages
01
STAGE 01 · WHAT IT ISL4 · FUNDAMENTALS

What is Point-in-Time Recovery (PITR).

Why this matters: The mechanism: understand how Point-in-Time Recovery (PITR) works from first principles.

Every ACID database writes state changes to an append-only transaction log (Write-Ahead Log in PostgreSQL, Redo/Binlog in MySQL) before dirty pages hit data files. PITR turns that log into an out-of-band time machine using two artifacts: a consistent physical base backup (pg_basebackup / pgBackRest) and an unbroken chain of archived 16 MB WAL segments starting from the backup's start LSN.

During recovery, you restore the base backup into a fresh cluster and replay WAL up to recovery_target_time, recovery_target_xid, recovery_target_lsn, or a named pg_create_restore_point(...).

Base Backup + WAL Replay

PITR Restoration Architecture (Base Snapshot + WAL Stream)

Base Backup (02:00)Start LSN 42/80000028S3 WAL ArchiveContinuous 16MB segsTarget Stop (11:14:07)action = 'pause'Timeline 00000002Verified & Promoted

1.1. Unbroken Chain: Every 16 MB WAL segment between the base backup LSN and target time must exist in object storage.

2.2. Pause & Verify: Set recovery_target_action = 'pause' to run read-only SELECT checks before promoting.

3.3. Timeline Isolation: Promotion increments the timeline ID (00000002) so new writes never overwrite Timeline 1 WAL.

Base backups bound RTO, while continuous WAL archiving bounds RPO to seconds or minutes.

02
STAGE 02 · WHY WE NEED ITL4 · FUNDAMENTALS

Why we need PITR (and why Replicas do not save you).

Why this matters: The problem: see what breaks without PITR under real concurrency or scale.

Daily pg_dump or storage snapshots leave up to 24 hours of unrecoverable data loss.

Worse, streaming replication and Multi-AZ standbys do not protect against human or application errors: an accidental TRUNCATE TABLE, DELETE without WHERE, or ransomware wipe replicates to every standby in milliseconds.

Design Trade-Off

Why we need PITR (and why Replicas do not save you)

Before · Unbounded Coupling
  • No backpressure on spikes
  • Implicit shared state
  • Cascading tail latency
After · Bounded & Observable
  • Explicit capacity budgets
  • Isolated failure domains
  • Predictable p99 latency
Engineering Decision Framework
Problem
How to implement Point-in-Time Recovery without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When concurrent writes contend on shared state, snapshots alone lose everything written since the last backup; PITR bounds data loss to your log-shipping interval by replaying committed changes up to the exact instant before corruption.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Point-in-Time Recovery experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

An Untested Archive Is a Broken Archive

A single missing 16 MB WAL segment halts replay at that LSN. Monitor pg_stat_archiver.failed_count and run monthly automated restore drills.

Named Restore Points Before Risky DDL

Run SELECT pg_create_restore_point('pre_migration') immediately before backfills or migrations so you have an exact, clock-skew-free stop target.

03
STAGE 03 · WHERE IT IS USEDL5 · APPLIED DESIGN

Where PITR is mandatory (and where logical/rebuild suffices).

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Think of Where PITR is mandatory (and where logical/rebuild suffices) as the intuition layer for Point-in-Time Recovery: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Use physical PITR on all authoritative OLTP databases; skip it for ephemeral caches or derived search indexes that rebuild faster from primary sources.

ChoiceWhat it buysWhat it costs
Good Candidate: Production OLTP Clusters (RPO < 5 min)Bounds data loss to `archive_timeout` (e.g., 60–300s) and spins up isolated forensic clones at historical timestamps.High-write clusters (4,000 TPS -> ~14 GB/hr WAL) require parallel WAL prefetch and object-storage lifecycle tuning.
Avoid: Ephemeral Redis Caches & Derived Search IndexesRebuild from the primary OLTP database or Kafka log rather than archiving WALs.Archiving volatile cache mutations wastes S3 IOPS and storage.
Avoid: Single-Row Oops on a 20 TB ClusterIf soft-deletes or logical table backups exist, surgical restore avoids replaying terabytes for one row.Physical PITR restores the entire cluster separately before you `pg_dump` the recovered table back.
04
STAGE 04 · HOW IT IS MANAGEDL5 · APPLIED DESIGN

How PITR Archiving & Safe Target Recovery are configured.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Think of How PITR Archiving & Safe Target Recovery are configured as the intuition layer for Point-in-Time Recovery: Operational control: configure bounds, failure handling, and safe production defaults.

Enable wal_level = replica, archive_mode = on, and archive_timeout = 300s (with pgBackRest or WAL-G for parallel LZ4/Zstd compression and checksums). During recovery, always set recovery_target_action = 'pause' first so you never overshoot and promote past the destructive transaction.

Lifecycle & Failure Recovery

How PITR Archiving & Safe Target Recovery are configured

admitsucceedbudget exceededInitializedProcessingInvariant MetDegraded Fallback
# PostgreSQL postgresql.auto.conf for safe PITR verification
restore_command = 'pgbackrest --stanza=prod-pg archive-get %f "%p"'
recovery_target_time = '2026-11-18 11:14:07.000 UTC'
recovery_target_inclusive = false
recovery_target_action = 'pause'
recovery_target_timeline = 'latest'
-- Verify recovered state while paused, then promote explicitly:
SELECT count(*) FROM users;
SELECT pg_wal_replay_resume(); -- or pg_promote()
05
STAGE 05 · ALTERNATIVESL6 · SCALE & TRADE-OFFS

Alternatives: Physical PITR vs. `pg_dump` vs. Copy-on-Write Snapshots.

Why this matters: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Think of Alternatives: Physical PITR vs. pg_dump vs. Copy-on-Write Snapshots as the intuition layer for Point-in-Time Recovery: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Balance RPO, RTO on multi-terabyte databases, and operational complexity.

ChoiceWhat it buysWhat it costs
Physical PITR (pgBackRest / WAL-G)Sub-second target precision, seconds-to-minutes RPO, and no table-locking SQL parse overhead.RTO scales with WAL volume since last base backup unless mitigated with daily incremental backups and parallel prefetch.
Logical Backups (`pg_dump`)Allows restoring a single dropped table directly into a live database.24-hour RPO gap and slow single/parallel SQL restore on >500 GB databases.
Cloud CoW Storage Snapshots (RDS/Aurora/ZFS)Near-instantaneous volume restore (low RTO) paired with managed WAL shipping.Cloud vendor lock-in and higher storage snapshot costs on high-churn volumes.
06
STAGE 06 · PRODUCTION ARCHITECTUREL7 · STAFF / PRINCIPAL

Production example: Rewinding Past a 11:14:07 `TRUNCATE`.

Why this matters: Production architecture: see how the components compose end to end under real load.

A 400 GB Postgres 16 cluster takes a pgBackRest full backup at 02:00 UTC and ships WALs to S3.

At 11:14:07.412 UTC an operator runs TRUNCATE TABLE users.

Forensic Restore Drill

Non-Destructive PITR Replay & Verification Sequence

SRE / OperatorS3 (pgBackRest)Recovery ClusterLive Primary1. Restore 02:00 base backup2. Parallel WAL fetch -> 11:14:073. Pause before TRUNCATE (verifyrows)4. Promote TL2 + export recoveredtable

Restoring into an isolated clone with `action='pause'` keeps production's Timeline 1 history intact.

07
STAGE 07 · PROBLEMS SOLVED & FURTHER DEEP DIVEL7 · STAFF / PRINCIPAL

Problems solved by PITR & Related Storage Concepts.

Why this matters: Applied problems: connect these internals to concrete system design and debugging scenarios.

Think of Problems solved by PITR & Related Storage Concepts as the intuition layer for Point-in-Time Recovery: Applied problems: connect these internals to concrete system design and debugging scenarios.

Explore WAL internals, PostgreSQL maintenance, and multi-region disaster recovery.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

When configuring a PostgreSQL PITR restore to recover from an accidental `DROP TABLE`, why should you set `recovery_target_action = 'pause'` instead of `'promote'`?

Recommended Learning Flow