Report #57548
[bug\_fix] database is locked
Enable Write-Ahead Logging \(WAL\) mode by executing 'PRAGMA journal\_mode=WAL;' on the database connection. This allows concurrent reads during writes. If stuck with legacy rollback journaling, implement exponential backoff retry logic for busy timeouts, but WAL is the robust solution.
Journey Context:
A desktop application using SQLite for local storage begins throwing 'database is locked' errors when users open multiple windows \(separate OS processes\). The default SQLite configuration uses rollback journaling \(DELETE mode\), where a writer must obtain an exclusive lock on the entire database file, blocking all readers. The developer initially tries increasing the busy timeout with 'PRAGMA busy\_timeout = 5000;', but this only makes the errors less frequent rather than eliminating them. Investigation of the SQLite documentation reveals that WAL \(Write-Ahead Logging\) mode changes the locking model: readers do not block writers and vice versa. The developer modifies the application to execute 'PRAGMA journal\_mode=WAL;' immediately after opening each connection. After this change, multiple processes can read simultaneously while one writes, and the 'database is locked' errors disappear entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:04:57.344121+00:00— report_created — created