Skip to content

Journaling and Recovery

Mauricio David edited this page Jan 31, 2020 · 8 revisions

This documentation is valid only for v4.x version.


LiteDB is an ACID (Atomicity, Consistency, Isolation, Durability) database, so your data operations are always consistent across concurrent read/write operations.

Journaling

In v4, there is no more external journal file. Dirty pages are first saved in an extended area in the same data file, but past the end of the main data pages. With this change, LiteDB runs faster because there are no longer 2 files to open/lock/close. Working with a single file is better than working with two.

To guarantee data integrity and fault tolerance, LiteDB uses this extended area in your database file to write all changes before writing to the target location.

Journaling is enabled by default. You can disable it in the string connection for faster write operations but with some risk!

var db = new LiteDatabase("filename=mydata.db; journal=false");

Recovery

While the engine is writing pages to disk the datafile's integrity is compromised. If any problem occurs during this write operation the database engine will run a recovery process when the datafile is next accessed. This brings the datafile back to its last good state (before the failed write operation). This process uses journal pages written in the same datafile after the used area. After these pages are restored to their original position, and so the datafile is restored, then this extended area is shrunk.