SQLite Pre-write log

Source: Internet
Author: User

      SQLite introduced wal (write-ahead-logging) in 3.7.0, the full name of the Wal is Write Ahead Logging, It is a mechanism for implementing atomic transactions in many databases, and SQLite uses the rollback journal mechanism to implement atomic transactions before introducing the Wal mechanism. The principle of the
      Rollback journal mechanism is that before modifying the data in a database file, the data in the modified page is backed up in another place before the modifications are written to the database file If the transaction fails, copy the backup data back, undo the modification, and if the transaction succeeds, delete the backup data and commit the changes. The principle of the
      wal mechanism is that the modification is not written directly to the database file, but to another file called the Wal, and if the transaction fails, the record in the Wal is ignored, the modification is revoked, and if the transaction succeeds, It will be written back to the database file at a later time to commit the changes.
      Synchronize the behavior of the Wal file and database file is called Checkpoint (checkpoint), it is automatically executed by SQLite, the default is when the Wal file accumulated to 1000 pages of modification; At the appropriate time, you can also manually execute checkpoint,sqlite to provide the relevant interface. After executing the checkpoint, the Wal file will be emptied.
      When reading, SQLite will search in the Wal file, find the last write point, remember it, and ignore the write point after this (this ensures that read and write and read can be executed in parallel); It determines whether the page in which the data is to be read is in the Wal file, and if so, reads the data in the Wal file, and if not, reads the data in the database file directly.
      When writing, SQLite writes it to the Wal file, but must guarantee exclusive writes, so writes cannot be executed in parallel.
      wal uses shared memory technology in the implementation process, so all the read and write processes must be on the same machine, otherwise, data consistency cannot be guaranteed.

WAL (write-ahead log, pre-write) file format (1)

WAL (write-ahead log, pre-write) file format (2)

Write-ahead Transaction Log

SQLite Pre-write log

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.