What are the different states of a transaction?
EasyConceptTransactions & ACID
Answer
A transaction moves through five states: active, partially committed, committed, failed and aborted. It starts in the active state and ends either committed or aborted.
- Active to partially committed: the transaction executes its reads and writes; once its last statement has run, it is partially committed, although the changes may still be only in memory.
- Partially committed to committed: the commit record is written to the log on disk, so the changes become permanent.
- Failed to aborted: an error, a constraint violation or a crash moves it to failed; after all its changes are rolled back, it is aborted, and the DBMS can restart it or kill it.
- A committed or aborted transaction is said to be terminated.
Example: Booking a train seat:
Active -> seat marked, payment in progress
Partially committed -> last UPDATE done, COMMIT issued
Committed -> commit record written; booking confirmed
(or) Failed -> payment declined
Aborted -> ROLLBACK releases the seat