Report #93393
[bug\_fix] database is locked / SQLITE\_BUSY \(SQLite\)
Enable WAL \(Write-Ahead Logging\) mode via \`PRAGMA journal\_mode=WAL;\` and set a busy timeout with \`PRAGMA busy\_timeout=5000;\` to allow readers and writers to coexist without exclusive locks.
Journey Context:
You're building a desktop Electron application using SQLite for local state. In development with a single user, everything works. After release, users report 'database is locked' errors when the background sync process tries to write while the UI is rendering a read-heavy dashboard. You investigate and discover that SQLite's default journal mode is DELETE, which requires an exclusive lock on the entire database file during writes, blocking all readers. You read the SQLite documentation on WAL mode and realize it writes changes to a separate -wal file, allowing readers to continue using the old database snapshot while writers append to the log. You modify your database initialization to execute \`PRAGMA journal\_mode=WAL;\` \(persisting the setting\) and add \`PRAGMA busy\_timeout=5000;\` so that if a brief lock conflict occurs, SQLite sleeps and retries rather than returning SQLITE\_BUSY immediately. The locking errors disappear and read latency remains stable during writes. The fix works because WAL mode implements MVCC for SQLite by separating read and write paths; the database file remains unchanged during transactions, eliminating the need for exclusive locks that cause contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:20:56.181253+00:00— report_created — created