Engineer Atlas
OverviewLearnInternalsModeling LabPlaygroundDatabase FinderRoadmapPracticeInterview
OverviewLearnInternalsModeling LabPlaygroundDatabase FinderRoadmapPracticeInterviewCheat SheetCompare
Database Engineering
  • Database Fundamentals
  • SQL
  • Relational Modeling
  • Normalization & Denormalization
  • Indexes
  • Query Execution & Optimization
  • Transactions
  • Concurrency & Isolation
  • PostgreSQL
  • Redis
  • NoSQL & Data Models
  • Vector Databases & Retrieval
  • Scaling
  • Distributed Databases
  • Caching
Database Internals
  • Overview
  • Build AtlasDB
  • Storage, Records & Pages
  • Index Internals
  • Buffer Management
  • WAL & Recovery
  • Transactions & MVCC Internals
  • LSM Trees
  • Query Engine
  • PostgreSQL & InnoDB Internals
  • Distributed Internals
  • Performance Internals
Database/Internals/WAL & Recovery
Database Internals

WAL & Recovery

What survives if the machine dies after COMMIT: the write-ahead log, checkpoints, redo, undo and the restart sequence — with a crash button.

Explains, from underneath:Transactions
Write-Ahead Logging
▶ interactive

COMMIT returns, the machine dies, the dirty page was never written. The naive fix — flush every dirty page at commit — costs random 8 KB writes per changed byte and still leaves torn pages. The write-ahead log appends a description of each change to a sequential file, fsyncs it at COMMIT, and lets data pages be written whenever convenient. LSNs order everything; checkpoints let the log be truncated.

Crash Recovery
▶ interactive

On restart the engine has a log and a set of page images that lag behind it by an unknown amount. Recovery finds the last checkpoint, scans the log forward to learn which transactions committed, replays every change whose page does not yet have it (redo, made idempotent by page LSNs), rolls back the transactions that never committed (undo — or, in PostgreSQL, nothing), and opens for business.

Engineer Atlas
GitHub·LinkedIn