SQLite’s write-ahead logging (WAL) mode improves concurrency by recording changed pages in a separate log instead of modifying the database file during a transaction. Readers combine the database with the log, while a single writer appends changes, allowing readers and the writer to proceed at the same time. The log stores complete page images, and chained checksums let SQLite detect damaged or incomplete writes. A transaction becomes visible when its valid commit frame is published in the shared wal-index; readers capture a fixed frame number as their snapshot, so later commits do not alter what they see. The wal-index maps pages to their newest logged versions and can be rebuilt from the log after a crash.
Checkpointing transfers logged pages into the database file, but cannot overwrite pages needed by readers holding older snapshots. SQLite offers passive, full, restart, and truncate checkpoints, with increasingly strict waiting and log cleanup. Automatic checkpoints normally begin after 1,000 pages, and the committing connection may bear their cost. WAL avoids undo recovery because uncommitted changes never reach the database file; after a crash, SQLite validates frames and ignores anything after the last valid commit. Important constraints remain: only one writer can operate at once, long-lived readers can prevent checkpoints and cause log growth, and WAL generally requires local shared-memory and file-lock support. NORMAL synchronization can lose recent commits after a crash but does not corrupt the database; FULL synchronization flushes the log at commit.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.