Transaction States
Transaction States
Definition
A transaction moves through a well-defined sequence of states during its lifetime: Active → Partially Committed → Committed, or, if something goes wrong: Active → Failed → Aborted.
How It Works
- Active: the transaction is executing its operations — the normal, initial state.
- Partially Committed: the transaction's final operation has executed, but the changes aren't yet guaranteed durable on disk — a brief transitional state before the engine confirms the write is safe.
- Committed: the transaction has successfully completed, and its changes are now permanent (durable, 22.8) — this is a terminal state; a committed transaction cannot be undone by a later
ROLLBACK. - Failed: something went wrong (a constraint violation, a system crash, a deadlock) after the transaction started but before it could commit — execution cannot continue normally.
- Aborted: the transaction has been rolled back after failing, restoring the database to its state before the transaction began — also a terminal state; from here, the transaction might be retried as an entirely NEW transaction (not resumed).
Edge Cases and Pitfalls
- Once a transaction reaches Committed, there is no way back — a mistake discovered after commit requires a NEW, separate transaction (perhaps a compensating one) to fix, not a rollback of the already-committed one.
- The transition from Active to Failed can be triggered by things entirely OUTSIDE the application's control (a server crash, a deadlock the database itself detects and resolves by aborting one of the involved transactions) — application code needs to handle "my transaction was aborted for reasons I didn't cause" as a real, expected scenario, not just self-inflicted rollbacks.
- "Partially committed" is a genuinely brief, often invisible state in practice — most discussions of transaction states simplify to Active/Committed/Aborted for everyday purposes, but the full five-state model matters for understanding exactly when durability (22.8) actually kicks in.
Key Takeaways
- The transaction state machine: Active -> Partially Committed -> Committed (success path), or Active -> Failed -> Aborted (failure path).
- Committed is a terminal, irreversible state — fixing a mistake after commit needs a new transaction.
- A transaction can fail for reasons outside the application's control (crashes, deadlocks) — this must be handled as a normal case.