One PRAGMA, two orders of magnitude
The default SQLite journal mode is DELETE: writers acquire an exclusive lock that blocks readers. WAL (Write-Ahead Logging) mode flips this — readers and writers don't block each other. Readers see a consistent snapshot; writers append to a log file (db-wal) which is periodically checkpointed back into the main database.
Turn it on once per database (it's persistent):
PRAGMA journal_mode = WAL;Why you almost always want it:
- Readers never block on writers, writers never block on readers.
- Writes are dramatically faster — fewer fsyncs, sequential append.
- It's the prerequisite for any concurrent workload (a web server, an async app, a desktop app with background sync).
Warning: WAL mode requires the database file to live on a real filesystem with proper file locking. It does not work safely on NFS, SMB, FUSE, or anything else with quirky locking semantics. Local disk only.
Pair WAL with a sensible busy_timeout (5–30 seconds) so transient locks during checkpoints just wait briefly instead of returning SQLITE_BUSY.