Database log
In computer science, in the field of databases, a Database Log is a history of actions executed by a database management system. Physically, a log is a file of records stored in stable storage, designed to withstand crashes.
Anatomy of a General Database Log
- A database log record is made up of (FIXME: resource managers, xid not universal)
-
- *Log Sequence Number: A unique id for a log record. With LSNs, logs can be recovered in constant time. Most logs' LSNs are assigned in monotonically increasing order, which is useful in recovery algorithms, like ARIES.
-
- *Prev LSN: A link to the last log record. This implies database logs are constructed in linked list form.
-
- *Transaction ID number: A reference to the database PostgreSQL), it might contain:
- redoLSN: This is a reference to the first log record that corresponds to a dirty page. i.e. the first update that wasn't flushed at checkpoint time. This is where redo must begin on recovery.
- undoLSN: This is a reference to the oldest log record of the oldest in-progress transaction. This is the oldest log record needed to undo all in-progress transactions.
- Completion Record notes that all work has been done for this particular transaction. (It has been fully committed or aborted)
Tables
These tables are maintained in memory, and can be efficiently reconstructed (if not exactly, to an equivalent state) from the log and the database:
- Transaction Table: The table contains one entry for each active transaction. This includes Transaction ID, and lastLSN, where lastLSN describes the LSN of the most recent log record for the transaction.
- Dirty Page Table: The table contains one entry for each dirty page that haven't been written to disk. The entry contains recLSN, where recLSN is the LSN of the first log record that caused the page to be dirty.
- TODO: Log Iteration and Interactions