SQLite Write-Ahead Logging (WAL) Concurrency Notes
SQLite's default rollback journal serializes readers behind writers. Switching to Write-Ahead Logging (PRAGMA journal_mode=WAL;) allows concurrent readers to observe consistent snapshots while a single writer appends frames to the -wal file.
1. Recommended Connection Pragmas
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA busy_timeout = 5000;
PRAGMA wal_autocheckpoint = 1000;
PRAGMA foreign_keys = ON;
2. Preventing WAL Unbounded Growth
Long-lived read transactions pin historical WAL frames and block PASSIVE checkpoints from resetting the write offset. Always close read cursors promptly and run periodic PRAGMA wal_checkpoint(TRUNCATE); during maintenance windows.