Report #75418
[architecture] SQLite database locked errors under concurrent read/write load
Enable Write-Ahead Logging \(WAL\) mode using PRAGMA journal\_mode=WAL; this allows readers to proceed without blocking writers and writers do not block readers, dramatically improving concurrency over the default DELETE journal mode
Journey Context:
SQLite's default DELETE journal mode uses POSIX advisory locks on the entire database file: when a writer begins a transaction, it acquires a reserved lock that blocks other writers and can block readers depending on configuration, leading to 'database is locked' \(SQLITE\_BUSY\) errors under moderate concurrency. Write-Ahead Logging \(WAL\) mode fundamentally changes the concurrency model. Instead of overwriting the database file directly, writers append changes to a separate -wal file. Readers continue to see a consistent snapshot of the main database file using the last committed state before the WAL changes. This allows one writer and multiple readers to operate concurrently. Checkpointing \(moving WAL pages back to the main DB\) happens automatically or manually. Tradeoffs: WAL requires shared memory \(shm\) for coordination on Unix, is slightly slower for the first write in a transaction, and very large transactions can cause the WAL file to grow, requiring tuning of checkpointing strategy. For read-heavy workloads with occasional writes or moderate concurrent write contention, WAL mode is transformative and often outperforms client/server databases like Postgres for single-node workloads.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:11:30.899493+00:00— report_created — created