Skip to content

Journaling and Recovery

Mauricio David edited this page Mar 28, 2015 · 8 revisions

LiteDB is an ACID (Atomicity, Consistency, Isolation, Durability) database, so your data transactions are always consistent across concurrency access.

Journaling

To guarantee data integrity and fail tolerance, LiteDB use a temporary file to write all changes before write on data file. Before write direct to disk, LiteDB create a temp file (called committed journal file) to store all dirty pages. The journal is always located in the same directory as the database file and has the same name as the database file except with the -journal appended.

  • If there is any error during write journal file, the transaction are aborted - and no changes are made on original data file.
  • After write all committed pages on journal file, LiteDB starts writing this pages on your data file. If occur an error at this moment, your data file is corrupted because not all pages was write. LiteDB needs re-write all pages again, using journal file. This recovery operation occurs when you try open database next time.
  • When all operation end journal file is deleted.

Journaling is enabled by default. You can disable on string connection to get a fast write operations with some risk!

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