Report #82473
[bug\_fix] sqlite3.OperationalError: database is locked
Enable Write-Ahead Logging \(WAL\) mode via \`PRAGMA journal\_mode = WAL;\` and set a busy timeout via \`PRAGMA busy\_timeout = 5000;\` \(milliseconds\) on every connection. Ensure these pragmas are executed immediately after opening each database connection.
Journey Context:
You deploy a Flask app using SQLite to production with 4 uWSGI workers. Under light load, it works. Under moderate load, you get 'database is locked' errors. You check the SQLite documentation and learn that in rollback journal mode \(default\), a writer gets an exclusive lock on the entire database. When one worker is writing, others get SQLITE\_BUSY immediately because you haven't set a busy timeout. You enable WAL mode, which allows readers to continue reading from the old snapshot while a writer writes to the WAL file. You also set busy\_timeout to 5000ms so that if a writer is active, other writers will wait rather than fail immediately. After these changes, your app handles 100 concurrent writers without errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:01:19.972200+00:00— report_created — created