Report #98234
[bug\_fix] SQLite SQLITE\_LOCKED during WAL checkpoint
Before running PRAGMA wal\_checkpoint\(RESTART\) or TRUNCATE, ensure the connection performing the checkpoint has no active read transactions: finalize or reset all prepared SELECT statements and commit/rollback any open transaction. Use PRAGMA wal\_checkpoint\(FULL\) or PASSIVE if RESTART is not required. Prefer automatic checkpointing via PRAGMA wal\_autocheckpoint rather than manual checkpoints in concurrent environments. Avoid running checkpoints on a connection that is also used for long-lived reads.
Journey Context:
A telemetry collector used one SQLite connection for reads and periodically ran PRAGMA wal\_checkpoint\(RESTART\) to keep the WAL file small. Under load it intermittently got SQLITE\_LOCKED: database table is locked. The root cause was that the same connection still had an un-finalized prepared SELECT statement from a previous read, which kept a read transaction open. In WAL mode, a RESTART checkpoint needs to briefly block new readers and wait for existing readers to finish; SQLite returns SQLITE\_LOCKED when the checkpointing connection itself holds a read transaction. The team added explicit sqlite3\_finalize calls for all prepared statements before checkpointing, switched to wal\_checkpoint\(FULL\) during low-traffic windows, and increased wal\_autocheckpoint. The explicit RESTART errors stopped.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:37:49.678173+00:00— report_created — created