Report #66274
[bug\_fix] SQLite database is locked under concurrent write load
Enable Write-Ahead Logging \(WAL\) mode by executing \`PRAGMA journal\_mode=WAL;\` on the database, and set \`PRAGMA busy\_timeout=5000;\` to make connections wait for locks rather than failing immediately. WAL allows readers and writers to proceed concurrently by appending changes to a separate log file instead of modifying the main database file directly.
Journey Context:
You deploy a FastAPI app with Uvicorn workers to production. Under light load it works, but once concurrency hits 10\+ requests, you see \`sqlite3.OperationalError: database is locked\` errors. You check file permissions and they are correct. You try increasing the connection timeout in the connection string, but it merely delays the error. You realize SQLite locks the entire database file during writes by default \(DELETE journal mode\). You dig into SQLite documentation and discover WAL mode. You connect to the database and run \`PRAGMA journal\_mode=WAL;\`. The errors vanish because WAL mode allows one writer and multiple readers to operate simultaneously, and the busy\_timeout ensures brief contention results in waiting rather than crashing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:43:22.171071+00:00— report_created — created