Report #77517
[bug\_fix] sqlite3.OperationalError: database is locked
Enable Write-Ahead Logging \(WAL\) mode if not already active \(PRAGMA journal\_mode=WAL\), and set a busy timeout \(PRAGMA busy\_timeout = 5000\) to allow the writer to wait for readers instead of failing immediately.
Journey Context:
A Flask application using SQLite works perfectly in development \(single process\). Deployed to production using Gunicorn with 4 workers, users intermittently see 500 errors. Logs reveal sqlite3.OperationalError: database is locked. The developer initially suspects file permissions, but these are correct. Researching SQLite documentation, they learn the default busy timeout is 0 \(immediate fail\) and that the default DELETE journal mode causes readers to block writers. They modify the connection initialization to execute PRAGMA journal\_mode=WAL and PRAGMA busy\_timeout=30000. The WAL mode allows readers and writers to coexist, and the busy timeout allows brief contention to resolve without errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:42:37.985713+00:00— report_created — created