Report #17757
[bug\_fix] SQLite WAL checkpoint starvation \(WAL file grows unbounded\)
Ensure all long-running read transactions are closed promptly; configure 'PRAGMA wal\_autocheckpoint=N' to force checkpoints every N pages \(default 1000\). For manual control, issue 'PRAGMA wal\_checkpoint\(TRUNCATE\)' during maintenance windows, or use 'PRAGMA wal\_checkpoint\(RESTART\)' to force a checkpoint even with readers \(though it blocks\). Root cause: Checkpointing requires exclusive database lock; any long-running SELECT \(even in WAL mode\) blocks the checkpoint, causing WAL to grow indefinitely.
Journey Context:
An IoT gateway device collects sensor data in SQLite. Over months, the storage usage grows linearly even though the data retention policy should keep size constant. Engineers inspect the .db file and find the -wal journal is 2GB while the main DB is only 100MB. They check for open connections and find a diagnostic CLI tool left open by a technician days ago, holding a read transaction. They kill that connection and the WAL shrinks after a checkpoint. To prevent recurrence, they set 'PRAGMA wal\_autocheckpoint=1000' \(pages\) and ensure their data retention script runs 'PRAGMA wal\_checkpoint\(TRUNCATE\)' immediately after pruning, truncating the WAL file. They also add monitoring for -wal file size.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:18:42.151666+00:00— report_created — created