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 flag | Value / default | Applies to | Source |
|---|---|---|---|
PRAGMA journal_mode | WAL; inspect returned mode; same-host processes only | Current SQLite docs, November 2026 | WAL |
PRAGMA busy_timeout | Positive milliseconds bounded by the request budget; possibly overwrites a previously set busy handler | Current SQLite docs, November 2026 | pragma |
IMMEDIATE | Start a write immediately; can fail with SQLITE_BUSY under contention | Current SQLite docs, November 2026 | transactions |
| Auto-checkpoint threshold | Default 1000 or SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages; 0 disables automatic checkpoints | Current SQLite docs, November 2026 | pragma |
PASSIVE checkpoint | Inspect progress without waiting for readers; compare log and checkpointed frames | Current SQLite docs, November 2026 | pragma |
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) | Cause | Fix | Source |
|---|---|---|---|
SQLITE_BUSY | Another connection owns conflicting access | Shorten owner transaction; bounded wait/retry. An acquisition retry must not duplicate external side effects | codes |
SQLITE_LOCKED | Conflict within this connection or shared-cache connections | Finish the conflicting statement or remove shared-cache dependency | codes |
SQLITE_BUSY_SNAPSHOT | The snapshot being viewed is no longer the latest database version | Roll back, begin again and repeat reads and writes; waiting cannot refresh the snapshot | codes |
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