Report #17475
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Enable Write-Ahead Logging \(WAL\) mode using 'PRAGMA journal\_mode=WAL;', set a busy timeout with 'PRAGMA busy\_timeout=5000;', and ensure transactions are as short as possible.
Journey Context:
You deploy a Flask application using SQLite to production with 4 Gunicorn workers. Under moderate load, you see 'database is locked' errors on write operations. Investigation reveals the default journal mode is DELETE, which requires an EXCLUSIVE lock on the entire database file for writes, blocking all other connections. You connect via sqlite3 CLI and run 'PRAGMA journal\_mode;' which returns 'delete'. You change it to WAL mode: 'PRAGMA journal\_mode=WAL;'. This allows readers to proceed without blocking the writer, and vice versa. You also add 'PRAGMA busy\_timeout=5000;' to connections so they wait up to 5 seconds for locks instead of failing immediately. The errors cease, though you note that WAL requires checkpointing \(PRAGMA wal\_checkpoint\) to prevent -wal files from growing indefinitely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:25:46.487590+00:00— report_created — created2026-06-17T05:46:50.685244+00:00— confirmed_via_duplicate_submission — confirmed