PostgreSQL WAL, full-page writes and checkpoints

synchronous_commit, full_page_writes, max_wal_size and checkpoint_timeout, and how replication slots can fill a disk.

More on PostgreSQL

Keep learning

Overview

off: up to 600 ms of acknowledged commits lost on a crash, never corruption. Settable per transaction. off: a power cut can corrupt the cluster. Only for throwaway data. fdatasync (Linux) How WAL is forced to disk. On macOS only fsync_writethrough flushes the drive cache. Measure with pg_test_fsync. off: less WAL, but torn pages become unrecoverable. pglz, lz4 or zstd compress full-page images: less WAL for some CPU. -1 (1/32 of shared_buffers, max 16 MB) Memory for WAL not yet written. Rarely the bottleneck. Longer: fewer full-page images and writes, longer crash recovery. Soft cap on WAL between checkpoints. Too small and WAL volume forces checkpoints early. Spread checkpoint writes over 90% of the interval to avoid I/O spikes. Logs a hint when WAL-forced checkpoints come closer than this. -1 (unlimited) Cap on WAL a slot may pin. Set it: losing a slot beats losing the primary. pg_stat_checkpointer (17) / pg_stat_bgwriter (16) Timed versus requested checkpoints, buffers written. WAL record appended 16 MB, current 16 MB, full data files (base/…) written later, in bulk checkpointer · bgwriter Rule: a data page may reach disk only after WAL up to its pd_lsn is flushed. COMMIT waits for the small sequential WAL write. The random page writes happen later, in the background. Torn page. An 8 kB page is written as two 4 kB blocks. Power fails after the first block: the page is half new and half old. A normal WAL record holds only the change, so replay cannot repair the old half. With full_page_writes the first change after a checkpoint logged the whole page, so replay restores the full image and then applies later changes. 1. 8 kB page, power cut mid-write 4 kB: new 4 kB: still old torn: checksum fails 2. replay a delta record “tuple 7: bal 50 → 70” needs a sane page to apply to ✕ cannot rebuild the old half FPI: whole 8 kB page, first change after checkpoint then later deltas ✓ overwrite, then replay The cost: one full page in WAL per page per checkpoint cycle. Short checkpoint spacing multiplies it. chapters · postgresql PostgreSQL WAL, full-page writes and checkpoints One log, the WAL, makes commits durable, repairs crashes, feeds replicas and powers point-in-time recovery. Its settings decide what a crash can cost and how hard the disk works.

2. synchronous_commit: what COMMIT waits for

Each level moves the point where COMMIT returns one step further down the pipe. off is the only level that can lose a commit on a single-server crash, and it never corrupts data: it is fine for click logs, wrong for payments. The remote levels only mean something when synchronous_standby_names lists a standby. Durability as a property is in ACID.

3. Torn pages and full_page_writes

After each checkpoint, the first change to any page logs the whole page (a full-page image, FPI). Recovery overwrites the torn page with it, then applies the later records.

4. Checkpoints: spacing, cost and recovery time

A checkpoint writes every dirty page, spread over checkpoint_completion_target of the interval, fsyncs the files and records a redo point. WAL before the redo point can then be recycled.

5. Archiving, replication and slots

Streaming replication. A walsender streams WAL to each standby, which replays it. A slot makes the primary keep every segment the consumer has not confirmed, and a dead consumer means WAL grows until the disk fills. See replication log.

Reference: settings and views

Defaults are PostgreSQL 16/17 Setting or view What it trades Compare: MySQL. InnoDB splits this into a redo log plus a separate binlog, with a doublewrite buffer instead of full-page images: see MySQL logs.

Recap

synchronous_commit picks where COMMIT returns: off risks the last ~600 ms, remote levels protect against losing the primary. full_page_writes logs a whole page after each checkpoint so torn pages can be repaired.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.