Report #86999
[bug\_fix] sqlite3.OperationalError: database is locked \(SQLITE\_BUSY\)
Enable WAL \(Write-Ahead Logging\) mode via \`PRAGMA journal\_mode = WAL;\` and set a busy timeout via \`PRAGMA busy\_timeout = 5000;\` \(milliseconds\). Root cause: Default journal mode \(DELETE\) requires exclusive locks for writes; concurrent writers or readers block each other, causing SQLITE\_BUSY if the lock isn't available immediately.
Journey Context:
You deploy a Flask app with SQLite to production using Gunicorn with 4 workers. Under load, users see 'database is locked' errors. You check the SQLite docs and realize the default journal\_mode=DELETE uses a single writer model. When two workers try to write simultaneously, one gets SQLITE\_BUSY. You change the connection setup to execute \`PRAGMA journal\_mode = WAL;\` immediately after connecting. Now reads and writes can overlap. You also add \`PRAGMA busy\_timeout = 10000;\` so that if a writer is blocked, it retries for 10 seconds instead of failing instantly. The errors cease.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:37:15.664435+00:00— report_created — created