Report #79364
[bug\_fix] sqlite3.OperationalError: database is locked \(SQLITE\_BUSY\)
Enable WAL mode \(PRAGMA journal\_mode=WAL\) to allow readers to not block writers, and set a busy timeout \(PRAGMA busy\_timeout = 5000\) so connections wait for locks instead of failing immediately.
Journey Context:
You deploy a Flask app using SQLite on a server with multiple gunicorn workers. Intermittently, writes fail with 'database is locked'. You check the SQLite docs and learn that the default locking mode \(DELETE journal mode\) uses a single writer, and the default busy timeout is 0, meaning it returns SQLITE\_BUSY immediately if the db is locked. You connect to the db manually and run PRAGMA journal\_mode; it returns 'delete'. You switch to WAL mode by executing PRAGMA journal\_mode=WAL; this allows readers to not block writers and vice versa, though still only one writer at a time. You also add PRAGMA busy\_timeout = 3000 to the connection initialization so it retries for 3 seconds before failing. The errors disappear and concurrency improves significantly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:48:31.072649+00:00— report_created — created