Report #68376
[bug\_fix] SQLITE\_BUSY during checkpoint or database is locked during write despite WAL mode enabled \(WAL checkpoint starvation\)
Ensure no long-running read transactions hold back the checkpoint by committing read transactions promptly, or disable auto-checkpoint \(\`PRAGMA wal\_autocheckpoint = 0;\`\) and manually execute \`PRAGMA wal\_checkpoint\(TRUNCATE\);\` during maintenance windows or low-traffic periods. Alternatively, increase the busy timeout to allow waiting for checkpoint completion. Root cause: In WAL mode, a checkpoint cannot progress beyond the frame \(page\) visible to the oldest active read transaction. Long-running reads \(analytical queries\) hold back the checkpoint, causing the -wal file to grow; when it reaches 1000 pages \(default\) or when a writer triggers a checkpoint, the checkpoint is blocked by the long reader, causing SQLITE\_BUSY for new writers.
Journey Context:
Your analytics desktop app uses SQLite with WAL mode for a local OLAP store. Users run a 'Monthly Report' that scans 2 million rows and takes 45 seconds. While this report runs, any attempt to insert new data fails with 'database is locked'. You check the -wal file and see it growing past 40MB. You run \`PRAGMA wal\_checkpoint;\` manually and it returns SQLITE\_BUSY \(1\), meaning the checkpoint couldn't complete. You query \`PRAGMA wal\_autocheckpoint;\` which returns 1000 \(pages\). You realize the long-running SELECT transaction \(started at frame 100\) is preventing the checkpoint from moving past frame 100, even though 1000 new pages have accumulated in the WAL. When a write triggers an auto-checkpoint at 1000 pages, it can't proceed, so new writers get SQLITE\_BUSY. You modify the reporting code to use a separate read-only connection that is closed immediately after the report, or you disable auto-checkpoint and run manual checkpoints during off-hours. The 'database is locked' errors during report generation disappear.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:15:09.169284+00:00— report_created — created