Skip to content
Contents/CH 22
Transactions & Recovery/Intermediate · 12 min

Transaction States

A transaction is not simply "running" or "done." It passes through states, and the DBMS makes different guarantees at each one.

In plain English

A transaction is like a parcel: packed, ready, shipped, delivered, or returned.

The one idea

Transaction states make commit and abort explicit: only a committed transaction is durable, and only an active or failed one can be rolled back.

Recovery decisions depend on where a transaction was when the system crashed. The state tells the recovery manager whether to redo or undo.

By the end

  1. 01Name the five transaction states.
  2. 02Trace normal and aborted execution paths.
  3. 03Explain the partially committed state.
  4. 04Know what happens after a failure.
01

The state diagram

A transaction starts active. It becomes partially committed after its last operation but before the commit is durable. Once the commit record is safely stored, it is committed. If an error occurs, it enters the failed state and then aborted after rollback. A terminated transaction has finished, whether committed or aborted.

chapter-22.db
active -> partially committed -> committed
   |                |
   v                v
 failed ---------> aborted
02

Normal execution

During the active state, the transaction reads and writes data and holds locks. In the partially committed state, all operations are done but the commit is not yet durable. The DBMS writes the commit record and flushes the log; then the transaction is committed and its locks can be released.

03

Failure and rollback

A failure can come from a constraint violation, a deadlock, a user ROLLBACK, or a system crash. The transaction enters the failed state, the recovery system undoes its changes using the log, and it becomes aborted. The application may retry with a new transaction.

Worked example3 steps

A crash in the partially committed window

T1 has executed its last statement but has not yet written the commit record.

01

The last write completes; T1 enters partially committed.

The changes may still be in memory or in an uncommitted log record.

02

The system crashes before the commit record is durable.

Recovery treats T1 as uncommitted and undoes its writes.

03

The commit record reaches disk before the crash.

Recovery redoes T1 if needed and makes the result visible.

ConclusionCommit is a durable event, not the moment the last SQL statement returns. The log record is the boundary.

Instrument

Watch it happen.

Step through one operation at a time

Step player01 / 06
01

BEGIN

The transaction starts and begins reading and writing data. Its changes are not visible to other transactions.

active
partially committed
committed
failed
aborted
eventBEGIN

The trade-off

No free correctness.

Gain

A precise recovery contract and a clear visibility rule.

Cost

A commit must force a log write, and that fsync is often the latency bottleneck.

Verdict

Batch commits when possible, but never report success before the commit record is durable.

Recap

What to keep.

Takeaways

  • +The five states are active, partially committed, committed, failed, and aborted.
  • +Partially committed means the work is done but the commit is not durable yet.
  • +Committed means the commit record is safely stored.
  • +Failed transactions are rolled back and become aborted.
  • +A terminated transaction is either committed or aborted.

Traps

  • !Thinking partially committed is already durable.
  • !Releasing locks before the commit is durable.
  • !Retrying a transaction without considering idempotence.

Focus

  • →Draw the state diagram.
  • →Explain the difference between partially committed and committed.
  • →Trace a crash before and after the commit record.

Check yourself

Before you turn the page.

0 / 2 answered
01

Which state means all operations are done but the commit is not yet durable?

02

What happens to a failed transaction?

DB//COSMOS

A field manual for database systems: model the domain, normalize the facts, query the relations, and protect the result.

Edition 2026 · 32 chaptersTopic catalogInterview prep