Report #13103
[bug\_fix] SQLiteException: database is locked \(SQLITE\_BUSY\)
Enable WAL \(Write-Ahead Logging\) mode \(PRAGMA journal\_mode=WAL\) which allows concurrent readers and a single writer without busy locks, eliminating SQLITE\_BUSY for readers; additionally set PRAGMA busy\_timeout=5000 to make connections wait for locks rather than failing immediately. Root cause: In the legacy DELETE or TRUNCATE journal modes, SQLite locks the entire database file exclusively for writes; any concurrent write attempt or sometimes read attempt returns SQLITE\_BUSY immediately unless the connection is configured to wait.
Journey Context:
Your Python Flask app with threaded request handling starts throwing 'sqlite3.OperationalError: database is locked' errors whenever two users submit data within milliseconds of each other. You check the connection strings and see no pooling issues. You realize SQLite is in the default DELETE journal mode. You attempt to add PRAGMA busy\_timeout=3000, which reduces errors but doesn't eliminate them under heavy load. You investigate WAL mode and find it allows one writer and multiple readers concurrently. You execute PRAGMA journal\_mode=WAL on the database, and the locking errors disappear entirely, though you now monitor the -wal and -shm files for growth.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:46:28.304879+00:00— report_created — created