Demonstrate the System Log in database transaction
Answer:-
System Log in Database Transactions
A system log is an essential part of DBMS transaction management. It keeps track of all operations performed during transactions, allowing the system to recover from failures and ensure ACID properties, especially atomicity and durability.
Purpose of the System Log
- Records all changes made during transactions
- Helps recover the database to a consistent state after crashes
- Supports rollback (undo) and redo operations
Types of Information in a Log Record
A typical log record contains:
- Transaction ID
- Type of operation (e.g., WRITE, COMMIT, ABORT)
- Data item affected
- Old value (before the change)
- New value (after the change)
- Timestamp
Types of Log Entries
Log Entry | Description |
---|---|
START | Indicates the beginning of a transaction |
WRITE | Logs changes: the old and new value of data |
COMMIT | Indicates successful completion of a transaction |
ABORT/ROLLBACK | Marks the cancellation of a transaction |
CHECKPOINT | Marks a save point to simplify recovery |
Example Log for a Transaction T1
Assume T1 updates Account A from ₹500 to ₹400.
[START, T1] [WRITE, T1, A, 500, 400] [COMMIT, T1]
Explanation:
- The transaction T1 begins
- It changes the value of A from 500 to 400
- It commits, making the change permanent
Crash and Recovery Scenario
If the system crashes after the WRITE
but before COMMIT
, the log will contain:
[START, T1] [WRITE, T1, A, 500, 400] -- Crash
- Since
COMMIT
is missing, T1 must be rolled back - Value of A is restored to 500
If COMMIT
was written before the crash, then redo is applied to ensure the update persists.
Checkpointing
- The DBMS periodically writes a checkpoint to the log like:
[CHECKPOINT, T1, T2]
- This reduces the recovery time by limiting how far back the system needs to look.
Summary Table
Component | Function |
---|---|
START | Begin transaction |
WRITE | Record old and new values of an update |
COMMIT | Confirm transaction success and durability |
ABORT/ROLLBACK | Cancel a transaction and restore original values |
CHECKPOINT | Establish a recovery snapshot for active transactions |