← Lessons

quiz vs the machine

Gold1410

Databases

The Checkpoint and Fsync

A checkpoint flushes dirty pages and records a safe recovery point so the write ahead log can be trimmed and restart stays fast.

5 min read · core · beat Gold to climb

Dirty Pages in Memory

After a transaction commits its WAL record, the changed data pages often still sit only in the buffer pool as dirty pages. Durability comes from the log, not yet from the data files. The log therefore keeps growing.

What a Checkpoint Does

A checkpoint brings the data files up to date and bounds recovery work.

  • It writes dirty pages from the buffer pool to the data files.
  • It issues an fsync so those writes are truly on durable storage.
  • It records a marker saying the log up to this point is fully reflected in the data files.

Why It Matters

  • The WAL before the checkpoint can be trimmed, keeping the log from growing without limit.
  • After a crash, recovery only needs to replay log written since the last checkpoint, so restart is fast.

Sharp Versus Fuzzy

A sharp checkpoint stalls writers while it flushes, giving a clean point but a pause. A fuzzy checkpoint flushes gradually in the background, avoiding a stall but recording a range that recovery must reconcile.

Key idea

A checkpoint flushes and fsyncs dirty pages, then records a recovery marker so the WAL can be trimmed and crash recovery only replays recent log.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does the WAL keep growing without checkpoints?

2. What does a checkpoint let the system trim?

3. How does a fuzzy checkpoint differ from a sharp one?