DBMS Notes
A transaction in a database system does not simply start and end — it passes through a well-defined sequence of states during its lifetime. Understanding...
Introduction
A transaction in a database system does not simply start and end — it passes through a well-defined sequence of states during its lifetime. Understanding these states is essential for implementing proper transaction management, recovery mechanisms, and concurrency control. The transaction state diagram describes every possible condition a transaction can be in, from the moment it begins executing until it either successfully completes or is rolled back.
State Transitions in Detail
| From State | To State | Trigger |
|---|---|---|
| Active | Partially Committed | Last statement executed successfully |
| Active | Failed | Error during execution (crash, deadlock, constraint) |
| Partially Committed | Committed | Changes successfully written to stable storage |
| Partially Committed | Failed | Unable to write to stable storage (disk full, crash) |
| Failed | Aborted | Rollback completed successfully |
| Aborted | Active (new transaction) | System decides to restart |
| Aborted | Terminated | System decides to kill |
Practical Example: Bank Transfer
| Transaction T | Transfer 1000 from Account A to Account B |
| READ(A) | A = 5000 |
| A = A - 1000 | A = 4000 |
| WRITE(A) | buffer updated |
| READ(B) | B = 3000 |
| B = B + 1000 | B = 4000 |
| WRITE(B) | buffer updated (last statement) |
| Scenario A | Success |
| All writes successful | State 3: COMMITTED |
| Scenario B | Failure (disk crash during flush) |
| Cannot guarantee persistence | State 4: FAILED |
| UNDO | Restore A = 5000 (from log's before-image) |
| UNDO | Restore B = 3000 (from log's before-image) |
| System decides | restart T (hardware glitch was temporary) |
Important Observations
- Committed and Aborted are terminal states — a transaction reaches one or the other, never both
- Partially Committed is not the same as Committed — the transaction can still fail at this point
- The transition from Partially Committed to Committed is the critical moment — this is when durability is guaranteed (commit record hits stable storage)
- Once committed, a transaction cannot be undone — to reverse its effects, a new compensating transaction must be executed
Comparison with Real-World Analogy
| Transaction State | Online Shopping Analogy |
|---|---|
| Active | Adding items to cart, entering shipping details |
| Partially Committed | Clicked "Place Order" — payment processing |
| Committed | Payment confirmed, order shipped |
| Failed | Payment declined, website error |
| Aborted | Order cancelled, refund issued |
Just as a declined payment cancels the entire order (atomicity), a failed transaction undoes all its database changes.
Continue the lesson path