What makes a database stall for a moment

Flush storms, checkpoint pressure, lock waits, cleanup lag and a cold cache cause short stalls. Know the signs and what smooths them.

More on Running a database in production

Keep learning

Overview

Flush storm Dirty-page %, checkpoint age, commits waiting for log space Foreground eviction No clean page to reuse, so a query writes a dirty page itself Queries waiting for a free page More flush bandwidth, lower dirty target Lock wait Lock waits now, longest wait, blocker Short transactions, lock timeouts on schema changes Cleanup lag Oldest transaction age, old-version backlog End old transactions, alert on age Stats refresh → plan flip Statistics refresh and the optimizer picks another plan Plan before vs after Bigger sample, index, plan hint Background I/O Backup, batch job or another tenant shares the disk Disk wait time, % busy Throttle, move to a replica, separate disk OS swap Swap-in / swap-out per second Smaller cache, reluctant swapping Background flush I/O budget Steady flushing, no backlog Too high: steals reads’ IOPS, rewrites hot pages Surge ceiling for flushing Catches up after bursts Short read slowdowns while it runs Dirty-page target (start early) Small backlog, rare storms More total writes Write-ahead log size More runway between checkpoints Longer crash recovery, more disk Checkpoint spread Checkpoint writes spread over the interval Slightly more log kept Stats auto-refresh threshold Fresh plans More chances of a plan flip Prove it Per-second p99 and max in the app, not the average. Find the beat Every minute? Every checkpoint? At :00? During backup? Read twice, subtract Which counter moved during the stall? Rule out Fix the workload first Short transactions, fewer dirty pages, throttled jobs. Check the disk A saturated device makes every cause look worse. chapters · running a database in production What makes a database stall for a moment Fast, then for a second a few queries take 100x longer, then fast again. Averages barely move. The cause is almost always a background duty that briefly takes priority.

1. A stall hides in the average and shows in p99

p99 is the latency 99% of requests beat. Short stalls touch few requests, so they lift p99 and max but not p50. A page that makes 30 queries often hits one slow one (see latency vs throughput).

2. The flush path and its three pressure points

Writes change pages in the cache and append to the write-ahead log. Background flushers write dirty pages to the data files, and a checkpoint lets the log be reused. Pressure point 1: log full, commits wait. Pressure point 2: no clean page, a query flushes one itself. Pressure point 3: flushing too hard, reads queue behind writes on the disk. Cache pages Write-ahead log reusable only after checkpoint 1 log full → commits wait 2 no clean page → query flushes 3 flushing hogs disk Causes, signals, levers What happens Background: checkpoints, the page cache, MVCC cleanup.

3. Stall detective: symptom, signal, fix

Start from the symptom, not a favourite setting. Ruling a cause out is as useful as confirming one. Counters are cumulative, so read twice and subtract.

4. Smoothing the flush: too low, too high

Budget too low: the backlog grows until the log is full, then a storm. Too high: flushing eats the disk and reads queue. Aim for steady, early, modest flushing with a surge ceiling and a log big enough to give runway. Knobs (generic) and what they trade

5. A routine for chasing jitter

A one-off slowdown right after a restart is a different problem: see cold reads. ⚙ In real engines MySQL: innodb_io_capacity(_max), innodb_max_dirty_pages_pct_lwm, innodb_redo_log_capacity (MySQL settings, logs). MySQL signals: Innodb_buffer_pool_wait_free, Innodb_log_waits, history list length (diagnostics, purge). PostgreSQL: max_wal_size, checkpoint_completion_target, background writer limits (WAL and checkpoints, settings). PostgreSQL cleanup lag is vacuum falling behind (MVCC and vacuum, locks).

Recap

Causes: flush storms, foreground eviction, lock waits, cleanup lag, plan flips, background I/O, swap. Flush early and steadily, keep a surge ceiling, give the log runway. Start from the symptom, read counters twice, change one thing, judge by the tail.

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.