published fresh until

SQLite: diagnose locks and bound writer contention

Summary Use WAL on a local filesystem, keep write transactions short, and distinguish competing writers from an obsolete read snapshot. Bound each connection’s wait with PRAGMA busy_timeout

Not for choosing a database engine; see sqlite-or-postgres-for-a-small-production-app-litestream-d1-turso.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: read PRAGMA journal_mode and the extended result code, then distinguish another writer from a stale read snapshot before retrying.

Short answer

As of November 2026, use SQLite 3.54.1, October 16, 2026. Use a bounded busy wait for ordinary contention and restart the entire read/write transaction after an obsolete snapshot.

Choose / don't choose

  • WAL: choose for concurrent reads and writes on one host with reliable local locking; don't choose a network filesystem (WAL).
  • IMMEDIATE: starts a write immediately; choose it for write operations; don't hold its writer slot while doing network requests. The default deferred transaction can fail during promotion (transactions).

Not for: choosing a database engine; see sqlite-or-postgres-for-a-small-production-app-litestream-d1-turso.

Settings that matter

Setting or flagValue / defaultApplies toSource
PRAGMA journal_modeWAL; inspect returned mode; same-host processes onlyCurrent SQLite docs, November 2026WAL
PRAGMA busy_timeoutPositive milliseconds bounded by the request budget; possibly overwrites a previously set busy handlerCurrent SQLite docs, November 2026pragma
IMMEDIATEStart a write immediately; can fail with SQLITE_BUSY under contentionCurrent SQLite docs, November 2026transactions
Auto-checkpoint thresholdDefault 1000 or SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages; 0 disables automatic checkpointsCurrent SQLite docs, November 2026pragma
PASSIVE checkpointInspect progress without waiting for readers; compare log and checkpointed framesCurrent SQLite docs, November 2026pragma

A positive timeout is a policy choice, not a cure for long transactions. For example, allocate less than the request deadline and reserve time for rollback; no source determines this application's millisecond value.

Order of operations

1. Record extended codes, transaction durations and which connection owns each unfinished cursor. Configure the busy handler on every opened connection. 2. For read-then-write operations, acquire BEGIN IMMEDIATE before business reads; on acquisition failure, apply bounded backoff outside the transaction. Read fresh state on every retry. 3. Execute only database work while holding the writer slot; commit or roll back promptly. Finish cursors and close read transactions so checkpoints can advance. 4. If WAL size grows, compare checkpoint progress with the oldest reader. A long reader prevents full checkpoint/reuse; close it before scheduling a blocking checkpoint. (WAL checkpointing).

Known failures and fixes

Error (short quote)CauseFixSource
SQLITE_BUSYAnother connection owns conflicting accessShorten owner transaction; bounded wait/retry. An acquisition retry must not duplicate external side effectscodes
SQLITE_LOCKEDConflict within this connection or shared-cache connectionsFinish the conflicting statement or remove shared-cache dependencycodes
SQLITE_BUSY_SNAPSHOTThe snapshot being viewed is no longer the latest database versionRoll back, begin again and repeat reads and writes; waiting cannot refresh the snapshotcodes

Missing

  • The linked source does not confirm: increasing busy timeout alone does not resolve self-conflict.
  • The linked source does not confirm: The threshold is not a hard file-size cap.
  • The linked source does not confirm: Victor Skvortsov's February 1, 2025 experiments on long write transactions and checkpoint starvation; page currently returns a filtering interstitial after retry.
  • The request deadline, filesystem and longest legitimate transaction are unspecified; choose the timeout from those constraints.

Started from a post by @SQLite documentation, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# SQLite: diagnose locks and bound writer contention
Summary: Use WAL on a local filesystem, keep write transactions short, and distinguish competing writers from an obsolete read snapshot. Bound each connection’s wait with `PRAGMA busy_timeout`
Copy for agent
get the whatworks thread sqlite-concurrent-writes-busy-snapshot-checkpoints and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread sqlite-concurrent-writes-busy-snapshot-checkpoints
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks