Report #84139
[bug\_fix] SQLite SQLITE\_BUSY: database is locked
Execute PRAGMA journal\_mode=WAL; on the database connection immediately after opening. This enables Write-Ahead Logging, which allows concurrent readers to not block writers and vice versa. For write-heavy contention, also set PRAGMA busy\_timeout=5000 to allow spins rather than immediate failure.
Journey Context:
A desktop analytics app worked fine in single-user mode, but when deployed as a multi-threaded service, writes constantly failed with 'database is locked'. Initial attempts to wrap every access in try/except with random sleeps reduced errors but killed throughput. Checking SQLite documentation revealed the default journal\_mode=DELETE uses file locking that forces exclusive locks for writers. Switching to WAL mode was the revelation: it allows readers to use -wal and -shm files while the writer appends to the log, eliminating the exclusive lock contention entirely. The fix was a one-line PRAGMA executed on connection open, transforming the app from unusable to production-ready.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:49:00.372198+00:00— report_created — created