Email arrives during an agent query
The sync worker inserts an email while the agent is paging through existing records.
SQLite, explained visually
Instead of changing the main database file during every transaction, SQLite appends committed changes to a write-ahead log. Readers assemble a stable snapshot from both places.
Traditional rollback journaling protects the old state before changing the database. WAL preserves the main file and records the new state elsewhere first.
The journal exists so SQLite can restore the old contents if the transaction fails.
A commit is recorded in the WAL. Copying those pages into the main file is a later checkpoint.
Use the controls to isolate each operation. Only the arrows that matter to the selected phase are shown.
WAL is not a queue or a second database. It is SQLite’s transactional path between a write and the main database file.
The sync worker inserts an email while the agent is paging through existing records.
A dashboard, an agent, and a backup inspection can read concurrently.
A reader holds an old end mark while new transactions accumulate.
gateway.dbThe durable main database. Checkpointing eventually copies committed WAL pages here.
gateway.db-walCommitted page changes not yet fully transferred into the main file. It is part of the database’s persistent state.
gateway.db-shmA shared-memory-backed index that helps readers quickly locate the newest applicable page in the WAL.
WAL mode is persistent for the database file. Check the returned value instead of assuming the request succeeded.
PRAGMA journal_mode=WAL;
-- expected result: wal
PRAGMA foreign_keys=ON;
PRAGMA busy_timeout=5000;
SQLite automatically attempts a checkpoint at roughly 1,000 WAL pages by default. Most small applications should begin with that default and measure before tuning.
A writer appends to the WAL instead of overwriting pages currently being read.
Its end mark stays fixed for the duration of the read transaction.
WAL improves read/write concurrency; it does not allow multiple simultaneous SQLite writers.
The WAL index relies on shared memory. Do not place a live WAL database on a network filesystem for access from different machines.
Close read transactions promptly so checkpoints can complete and the WAL can be recycled.
Do not copy only the .db file while live WAL state exists. Use SQLite’s backup facilities or a coordinated snapshot.
A read chooses a snapshot. A write appends committed changes. A checkpoint copies those changes home. WAL improves concurrency without turning SQLite into a multi-writer or distributed database.