Report #26259
[bug\_fix] SQLite: database is locked \(SQLITE\_BUSY\)
Enable WAL \(Write-Ahead Logging\) mode by executing PRAGMA journal\_mode=WAL; on the database connection. This allows concurrent readers to proceed while a writer is active. Additionally, set a busy timeout \(PRAGMA busy\_timeout=5000;\) to have SQLite automatically retry locked operations before returning SQLITE\_BUSY to the application.
Journey Context:
A Python Flask application using SQLite for a small SaaS starts throwing 'sqlite3.OperationalError: database is locked' errors as user concurrency increases. The developer initially adds a retry loop in Python with sleep, reducing but not eliminating the errors. Researching the SQLite file locking documentation, they understand that in the default DELETE journal mode, a writer must obtain an exclusive lock on the entire database file, blocking all readers and other writers. They execute PRAGMA journal\_mode=WAL; via the sqlite3 CLI and persist it in the application initialization. Under WAL mode, reads no longer block writes and vice versa; the application handles 10x concurrency without 'database is locked' errors, with only a slight increase in -wal file size.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:28:53.826316+00:00— report_created — created