Recent from talks
Nothing was collected or created yet.
Transaction log
View on WikipediaIn the field of databases in computer 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 used to guarantee ACID 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 systems, a journal is the record of data altered by a given process.[1][2][3][4]
Anatomy of a general database log
[edit]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 algorithms, like ARIES.
- Prev LSN: A link to their last log record. This implies database logs are constructed in linked list 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
[edit]This section needs additional citations for verification. (July 2016) |
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), 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
[edit]Sources
[edit]References
[edit]- ^ Microsoft, The Transaction Log (SQL Server)
- ^ sqlshack.com, A beginner’s guide to SQL Server transaction logs, February 11, 2014 by Ivan Stankovic
- ^ techrepublic.com, Understanding the importance of transaction logs in SQL Server, SQL Server transaction log maintenance, By Crowe, Chizek, November 11, 2004
- ^ neurobs.com, Logfiles
Transaction log
View on GrokipediaOverview
Definition
A transaction log in database systems is a sequential, append-only file that records all changes made by database transactions before those changes are applied to the database itself. This structure captures the history of operations such as inserts, updates, and deletes in a linear sequence, often using log sequence numbers (LSNs) to track the order and state of modifications.[4] The core purpose of a transaction log is to ensure durability by persisting modifications in non-volatile storage, such as disk, which allows the database state to be reconstructed after system failures like crashes or power losses. By writing log records to stable storage ahead of or concurrently with data updates—a principle known as write-ahead logging (WAL)—the log serves as a reliable source for replaying committed transactions (redo) or undoing uncommitted ones (undo) during recovery.[5] Unlike audit logs, which are designed for human-readable analysis to support compliance, security monitoring, and detection of unauthorized access, transaction logs are machine-readable formats optimized for automated recovery processes rather than manual auditing.[4] For example, a log entry for an INSERT operation might include the transaction identifier, timestamp, operation type (INSERT), the affected table and page, and the after-image of the newly inserted data to enable precise reconstruction if needed.[4][6]Purpose and Importance
Transaction logs play a crucial role in database management systems by enabling the enforcement of the ACID properties—Atomicity, Consistency, Isolation, and Durability—that ensure reliable transaction processing. For atomicity, logs record changes in a way that allows uncommitted transactions to be undone (rolled back) after failures, treating the transaction as a single, indivisible unit. Consistency is maintained by logging all modifications, which permits verification and restoration of data to a valid state adhering to integrity constraints. Durability is achieved by ensuring that once a transaction is committed, its effects are persistently recorded in the log, surviving system crashes or power failures.[5] A primary function of transaction logs is to prevent data loss and corruption in the event of failures, by providing a sequential record of all database modifications. This allows committed transactions to be redone (reapplied) to restore lost changes, while uncommitted ones can be undone to revert partial updates, thereby preserving the database's integrity post-recovery. Without such logging, failures could lead to inconsistent states, data inconsistencies, or permanent loss of committed work.[2] Transaction logs emerged in the 1970s as a foundational mechanism in early relational database systems, notably with IBM's System R prototype, to address recovery challenges in multi-user environments. Developed at the IBM San Jose Research Laboratory and detailed in 1976, System R introduced logging techniques to support concurrent transactions and robust failure recovery, laying the groundwork for modern database reliability.[7] In contemporary high-availability databases, transaction logs are indispensable for systems processing millions of transactions per second, facilitating features like replication, point-in-time recovery, and fault tolerance in distributed setups. For instance, advanced systems leverage logs to achieve throughputs exceeding 1 million transactions per second while maintaining durability and consistency across nodes.[8]Anatomy
Log Record Components
A log record in a transaction log captures the details of a specific database operation to ensure durability and enable recovery. Key components typically include the Transaction ID (TID), which uniquely identifies the transaction responsible for the operation; the Log Sequence Number (LSN), serving as a unique, monotonically increasing identifier that acts as the record's address in the log; the Page ID, specifying the data page affected by the operation; the operation type, indicating the nature of the action such as an insert, update, or delete; the before-image (also known as undo data), providing the original state of the modified data for potential reversal; the after-image (or redo data), containing the new state to allow reapplication of changes; and a checksum, computed to verify the integrity of the record and detect corruption. These elements are standardized in influential systems like ARIES to support atomicity and consistency.[5][9] The LSN is central to log management, assigned sequentially as each record is appended to the log, ensuring a total order of all operations across transactions. This monotonicity facilitates efficient navigation and comparison during recovery processes. To support traversal of a single transaction's history, log records include pointers such as PrevLSN, which references the LSN of the immediately preceding record written by the same transaction; this backward linkage allows quick access to prior actions without scanning the entire log. In some implementations, additional fields like UndoNxtLSN appear in specific record types to guide rollback operations.[5] Log records are engineered for compactness to reduce storage requirements and I/O overhead, with variable sizes influenced by the extent of logged data—headers alone may span 24-32 bytes, while full records remain on the order of hundreds of bytes in practice. This efficiency is crucial in high-throughput environments where millions of records may be generated per hour.[5][10] Example: Update Log Record Format Consider an update operation changing a field value from 10 to 20 on a specific page. A representative log record might include:| Component | Value/Description |
|---|---|
| LSN | 0x12345678 (monotonically increasing) |
| TID | Txn-001 (transaction identifier) |
| Page ID | Database:1, Table:5, Page:42 |
| Operation Type | Update |
| Before-Image (Undo) | Value: 10 |
| After-Image (Redo) | Value: 20 |
| PrevLSN | 0x12345670 (previous record for this TID) |
| Checksum | CRC-32: 0xABCDEF01 |
