Report #99158
[bug\_fix] SQLite WAL mode readers see stale snapshot / "database is locked" on checkpoint
Understand that WAL readers see the database as of the start of their transaction, so long-running read transactions block WAL checkpoints and can cause the -wal file to grow indefinitely. Set PRAGMA busy\_timeout high enough for the checkpoint to wait, and avoid long-lived read transactions. Run PRAGMA wal\_checkpoint\(TRUNCATE\) only during maintenance windows. If the -wal file is growing, find long-running readers with PRAGMA wal\_checkpoint\(PASSIVE\) status and reduce transaction lifetime. Use PASSIVE checkpoints during normal operation and RESTART/TRUNCATE only when idle.
Journey Context:
A telemetry collector wrote batches every second to a SQLite WAL database while a separate analytics script held a read transaction open for minutes. Over a day the -wal file grew to 40 GB and disk alerts fired. The team first tried manual PRAGMA wal\_checkpoint\(TRUNCATE\), which hung because the long read transaction held back the checkpoint. They killed the analytics reader; the checkpoint completed and the WAL shrank. The permanent fix was to rewrite the analytics job to open a transaction only for the duration of each query batch, and to schedule a PASSIVE checkpoint after each batch. This kept the WAL bounded and readers no longer blocked writers because WAL readers use snapshot isolation rather than table locks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:39:59.511970+00:00— report_created — created