Report #14300
[bug\_fix] database is locked \(SQLITE\_BUSY\) - write contention
Enable Write-Ahead Logging \(WAL\) mode \(PRAGMA journal\_mode=WAL\) and set a busy timeout \(PRAGMA busy\_timeout = 5000\) to allow writers to wait for locks rather than failing immediately.
Journey Context:
You deploy a Python Flask app using SQLite in production with multiple gunicorn workers. Under load, users see 'sqlite3.OperationalError: database is locked'. You check the database and see the -journal file appearing and disappearing. You realize that in the default DELETE journal mode, a writer gets an exclusive lock on the entire database, blocking all other readers and writers. Your multiple workers are hitting the DB simultaneously, causing contention. You try reducing gunicorn workers to 1, which 'fixes' it but kills performance. You try adding retry loops in Python, which helps but adds latency. The real fix is executing 'PRAGMA journal\_mode=WAL' to enable Write-Ahead Logging, where readers don't block writers and writers don't block readers \(mostly\), and setting 'PRAGMA busy\_timeout=5000' so that if a writer does encounter a busy lock, it waits up to 5 seconds instead of returning SQLITE\_BUSY immediately. This allows concurrent reads and a single writer to queue gracefully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:13:51.106811+00:00— report_created — created