Report #12033
[bug\_fix] SQLite WAL file grows indefinitely \(-wal file ballooning to gigabytes\)
Ensure no long-running read transactions prevent checkpointing. Commit read transactions immediately after use. During maintenance windows, execute PRAGMA wal\_checkpoint\(TRUNCATE\); to force WAL reset. For applications with continuous readers, implement a busy-timeout and ensure checkpoints run via the wal\_autocheckpoint pragma \(default 1000 pages\) by avoiding perpetual read locks.
Journey Context:
An IoT edge gateway uses SQLite in WAL mode to store sensor readings locally before batch upload. After weeks of continuous operation, the device reports 'disk full' despite the database supposedly holding only the last 7 days of data \(configured to purge old records\). Investigation reveals the -wal file has grown to 50GB while the main .db file is only 200MB. In WAL mode, data is first appended to the write-ahead log; a checkpoint operation moves committed data from the WAL to the main database file and then truncates the WAL. However, a checkpoint cannot complete if any active read transaction exists that might need to read pages from the WAL \(old snapshots\). The edge device had a background analytics thread that executed a SELECT query and kept the transaction open indefinitely to 'monitor' for thresholds, never committing. This held back the checkpoint, causing the WAL to grow unbounded as new writes accumulated. The fix required refactoring the monitoring to use short-lived transactions or file-change notifications, and implementing an explicit checkpoint during the device's nightly maintenance window.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:53:17.902375+00:00— report_created — created