Fly.ioExplainer
How SQLite helps you do ACID
Summary
SQLite’s rollback journal provides atomicity, isolation, and durability by preserving database state before a transaction changes the main file. Without journaling, an interrupted 4KB page write could corrupt the database; the journal instead records original pages, then permits recovery if commit steps fail. A journal header stores a nonce, the database’s pre-transaction page count, sector size, and page size, while each page record includes its page number, a copy of prior contents, and a 32-bit checksum. The mode allows concurrent readers but makes writers wait for readers and blocks new readers, using SHARED, RESERVED, and PENDING filesystem locks. Its simplicity brings a concurrency bottleneck; WAL and wal2 provide better support for concurrent readers, which the post says will be covered next.
Context
SQLite must ensure that transactions do not leave partially written pages, expose inconsistent views to readers, or fail to flush committed bytes to disk. The rollback journal addresses these atomicity, isolation, and durability requirements, while its locking behavior creates trade-offs for concurrent workloads.
Approach / What changed
SQLite writes the pre-transaction database state to a rollback journal, including a header and page records with page numbers, original page contents, and checksums. It syncs the journal before commit and deletes it to complete the transaction; filesystem locks coordinate readers and writers.
Takeaways
The rollback journal stores original database pages before they are changed, allowing SQLite to restore the prior state if a transaction fails before commit.
Rollback-journal mode permits multiple read-only transactions but allows only one write transaction and blocks new readers while that write completes.
SQLite’s rollback journal can bottleneck concurrent applications because writes wait for readers; WAL and wal2 were introduced to improve support for concurrent readers.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.