In the field of
database
In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
s in
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a transaction log (also transaction journal, database log, binary log or audit trail) is a history of actions executed by a
database management system
In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and an ...
used to guarantee
ACID
An acid is a molecule or ion capable of either donating a proton (i.e. Hydron, hydrogen cation, H+), known as a Brønsted–Lowry acid–base theory, Brønsted–Lowry acid, or forming a covalent bond with an electron pair, known as a Lewis ...
properties over
crashes or hardware failures. Physically, a log is a
file listing changes to the database, stored in a stable storage format.
If, after a start, the database is found in an
inconsistent state or not been shut down properly, the database management system reviews the database logs for
uncommitted transactions and
rolls back the changes made by these
transactions. Additionally, all transactions that are already committed but whose changes were not yet materialized in the database are re-applied. Both are done to ensure
atomicity and
durability of transactions.
This term is not to be confused with other, human-readable
logs that a database management system usually provides.
In
database management system
In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and an ...
s, a journal is the record of data altered by a given process.
neurobs.com, Logfiles
/ref>
Anatomy of a general database log
A database log record is made up of:
*''Log Sequence Number'' (LSN): A unique ID for a log record. With LSNs, logs can be recovered in constant time. Most LSNs are assigned in monotonically increasing order, which is useful in recovery algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s, like ARIES.
*''Prev LSN'': A link to their last log record. This implies database logs are constructed in linked list
In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes whi ...
form.
*''Transaction ID number'': A reference to the database transaction generating the log record.
*''Type'': Describes the type of database log record.
*Information about the actual changes that triggered the log record to be written.
Types of database log records
All log records include the general log attributes above, and also other attributes depending on their type (which is recorded in the ''Type'' attribute, as above).
*Update Log Record notes an update (change) to the database. It includes this extra information:
**''PageID'': A reference to the Page ID of the modified page.
**''Length and Offset'': Length in bytes and offset of the page are usually included.
**''Before and After Images'': Includes the value of the bytes of page before and after the page change. Some databases may have logs which include one or both images.
*Compensation Log Record (CLR) notes the rollback of a particular change to the database. Each corresponds with exactly one other Update Log Record (although the corresponding update log record is not typically stored in the Compensation Log Record). It includes this extra information:
**''undoNextLSN'': This field contains the LSN of the next log record that is to be undone for transaction that wrote the last Update Log.
*Commit Record notes a decision to commit a transaction.
*Abort Record notes a decision to abort and hence roll back a transaction.
*Checkpoint Record notes that a checkpoint has been made. These are used to speed up recovery. They record information that eliminates the need to read a long way into the log's past. This varies according to checkpoint algorithm. If all dirty pages are flushed while creating the checkpoint (as in PostgreSQL
PostgreSQL ( ) also known as Postgres, is a free and open-source software, free and open-source relational database management system (RDBMS) emphasizing extensibility and SQL compliance. PostgreSQL features transaction processing, transactions ...
), 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)
See also
* Data logging
* Error correction and detection
*Hash function
A hash function is any Function (mathematics), function that can be used to map data (computing), data of arbitrary size to fixed-size values, though there are some hash functions that support variable-length output. The values returned by a ...
*Journaling file system
A journaling file system is a file system that keeps track of changes not yet committed to the file system's main part by recording the goal of such changes in a data structure known as a " journal", which is usually a circular log. In the ev ...
* Log-structured file system
* Write-ahead logging
* Redo log
Sources
* Federal Standard 1037C
References
{{DEFAULTSORT:Transaction Log
Database management systems
Transaction processing
Computer logging