Transaction States
Definition
Transaction states are the different stages through which a database transaction passes during its lifetime, such as active, partially committed, committed, failed, and aborted, depending on whether operations are being executed, completed successfully, or terminated due to an error.
In simple terms, a transaction state shows the current status of a transaction while the database system is processing it.
Main Content
1. Transaction State Model
- A transaction moves through a fixed set of states from beginning to end. These states represent whether the transaction is executing, waiting, successfully completed, or stopped due to an error.
- The standard transaction state model includes:
- Active: The transaction is currently executing its read/write operations.
- Partially Committed: The last operation has been executed, but changes are not yet permanently saved.
- Committed: All updates are successfully stored permanently in the database.
- Failed: The transaction cannot continue due to an error, system crash, deadlock, or violation.
- Aborted: The transaction has been rolled back, and its effects are removed.
- Terminated: The transaction has finished completely, either after commit or abort.
A simple flow of transaction states can be represented as:
Start
|
v
Active ---> Failed ---> Aborted ---> Terminated
|
v
Partially Committed ---> Committed ---> Terminated
This model is important because it allows the DBMS to know exactly what action to take next, especially during recovery after failures.
2. Detailed Transaction States
Active State
- The transaction begins here after the
BEGIN TRANSACTIONcommand. - All database operations such as
read,write,update, anddeleteare performed in this state. - The transaction may remain active for a short or long time depending on complexity.
- Example: An online banking transfer reading the sender’s balance and subtracting money is in the active state.
Partially Committed State
- The transaction has executed its final statement successfully.
- However, changes are not yet guaranteed to be permanent because they may still be in memory or temporary storage.
- At this stage, the DBMS checks whether it is safe to write changes permanently.
- Example: After completing all operations of a money transfer, the transaction waits before final commit.
Committed State
- The transaction has completed successfully.
- All updates are permanently written to the database.
- Even if the system crashes later, committed changes remain preserved.
- Example: After a successful purchase order, the order record is permanently stored.
Failed State
- The transaction cannot proceed because something went wrong.
- Causes include:
- Logical errors
- Disk failure
- Deadlock
- Constraint violation
- Power failure
- The DBMS marks it as failed and prepares to undo its changes.
Aborted State
- The DBMS rolls back all effects of the failed transaction.
- The database is restored to the state before the transaction started.
- Some transactions may be restarted after abort, depending on the cause.
- Example: If a transfer fails after debiting one account but before crediting another, rollback restores the original balance.
Terminated State
- The transaction has ended completely.
- Resources such as locks, memory, and transaction logs are released.
- No further action is taken on the transaction.
3. State Transitions and Their Meaning
- A transaction does not jump randomly between states; transitions occur based on success or failure of operations.
- Common transitions include:
- Active → Partially Committed
- Occurs when the last statement executes successfully.
- Partially Committed → Committed
- Occurs when the DBMS confirms that all changes are safely stored.
- Active → Failed
- Occurs if an error prevents the transaction from continuing.
- Partially Committed → Failed
- Occurs if a failure happens before the commit becomes permanent.
- Failed → Aborted
- The DBMS performs rollback to undo changes.
- Committed / Aborted → Terminated
- The transaction ends and resources are released.
A more complete transition view:
+--------+
| Active |
+--------+
| |
| +----------------------+
| |
v v
+-------------------+ +--------------+
| Partially | | Failed |
| Committed | +--------------+
+-------------------+ |
| v
v +-----------+
+----------+ | Aborted |
| Committed| +-----------+
+----------+ |
| v
v +-------------+
+-------------+ | Terminated |
| Terminated | +-------------+
+-------------+
These transitions support recovery and ensure that the DBMS can handle normal execution as well as unexpected failures.
Working / Process
1. Transaction Begins and Enters Active State
- The transaction starts when a user/application issues a request, such as inserting a record or transferring money.
- The DBMS may assign a transaction ID and may also acquire locks if needed to maintain isolation.
- During this stage, all operations are only being executed, not yet made permanent.
2. Transaction Moves Through Execution and Either Commits or Fails
- If all operations complete successfully, the transaction enters the partially committed state.
- The DBMS then writes the log records and flushes necessary data to stable storage.
- If any problem occurs at any point, the transaction goes to the failed state instead.
3. Transaction Ends by Commit or Rollback
- If the transaction succeeds, it reaches the committed state and becomes permanent.
- If it fails, the DBMS rolls it back, moving it to the aborted state.
- Finally, the system releases locks and resources, and the transaction becomes terminated.
Advantages / Applications
Ensures correctness of database operations
- By tracking transaction states, the DBMS prevents partial updates from corrupting data.
- This is especially important when multiple operations must all succeed together.
Supports recovery after failures
- If a crash or error occurs, transaction states help the system decide whether to undo or preserve changes.
- This makes database systems reliable in banking, e-commerce, and reservation systems.
Helps manage concurrency and control resources
- Transaction states allow the DBMS to know when locks can be released and when a transaction is safe to finalize.
- This improves system stability and supports simultaneous access by many users.
Summary
- Transaction states describe the life cycle of a database transaction from start to finish.
- The main states are active, partially committed, committed, failed, aborted, and terminated.
- These states help the DBMS ensure safe execution, rollback on failure, and permanent storage on success.
- Important terms to remember: active, partially committed, committed, failed, aborted, terminated, rollback, commit