Open In App

Transaction States in DBMS

Last Updated : 16 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A transaction in DBMS is a sequence of operations performed as a single logical unit of work (e.g., transferring money between accounts). All operations in a transaction are executed together to ensure consistency. Transaction state represents the current stage of a transaction, indicating its progress and whether it completes successfully or fails.

  • A transaction goes through several states during its lifetime.
  • A transaction log is used to keep a record of all the steps taken during the transaction.
  • A transaction involves two main operations, Read Operation and Write Operation.
  • Read Operation: Reads data from the database, stores it temporarily in memory (buffer), and uses it as needed.
  • Write Operation: Updates the database with the changed data using the buffer.

Note: From the start of executing instructions to the end, Read and Write operations are treated as a single transaction. This ensures the database remains consistent and reliable throughout the process.

Different Types of Transaction States in DBMS

These are the different types of Transaction States:

  1. Active State
  2. Partially Committed State
  3. Failed State
  4. Aborted State
  5. Committed State
  6. Terminated State
transition_states_in_dbms
Transaction States

1. Active State

  • It is the first stage of any transaction when it has begun to execute. The execution of the transaction takes place in this state.
  • Operations such as insertion, deletion, or updation are performed during this state.
  • During this state, the data records are under manipulation and they are not saved to the database, rather they remain somewhere in a buffer in the main memory.

2. Partially Committed

  • The transaction has finished its final operation, but the changes are still not saved to the database.
  • After completing all read and write operations, the modifications are initially stored in main memory or a local buffer. If the changes are made permanent in the database then the state will change to "committed state" and in case of failure it will go to the "failed state". 

3. Committed

This state of transaction is achieved when all the transaction-related operations have been executed successfully along with the Commit operation, i.e. data is saved into the database after the required manipulations in this state. This marks the successful completion of a transaction.

4. Failed State

If any of the transaction-related operations cause an error during the active or partially committed state, further execution of the transaction is stopped and it is brought into a failed state. Here, the database recovery system makes sure that the database is in a consistent state.

5. Aborted State

If a transaction reaches the failed state due to a failed check, the database recovery system will attempt to restore it to a consistent state. If recovery is not possible, the transaction is either rolled back or cancelled to ensure the database remains consistent.

In the aborted state, the DBMS recovery system performs one of two actions:

  • Kill the transaction: The system terminates the transaction to prevent it from affecting other operations.
  • Restart the transaction: After making necessary adjustments, the system reverts the transaction to an active state and attempts to continue its execution.

6. Terminated State

It refers to the final state of a transaction, indicating that it has completed its execution. Once a transaction reaches this state, it has either been successfully committed or aborted. In this state, no further actions are required from the transaction, as the database is now stable.

Example of Transaction States

Imagine a bank transaction where a user wants to transfer $500 from Account A to Account B. The system should handle the following transaction states:

1. Active State:

  • The transaction begins. It reads the balance of Account A and checks if it has enough funds.
  • Example: Read balance of Account A = $1000.

2. Partially Committed State:

  • The transaction performs all its operations but hasn’t yet saved (committed) the changes to the database.
  • Example: Deduct $500 from Account A's balance ($1000 - $500 = $500) and temporarily update Account B's balance (add $500).

3. Committed State:

  • The transaction successfully completes, and the changes are saved permanently in the database.
  • Example: Account A’s new balance = $500; Account B’s new balance = $1500. Changes are written to the database.

4. Failed State:

  • If something goes wrong during the transaction (e.g., power failure, system crash), the transaction moves to this state.
  • Example: System crashes after deducting $500 from Account A but before adding it to Account B.

5. Aborted State:

  • The failed transaction is rolled back, and the database is restored to its original state.
  • Example: Account A's balance is restored to $1000, and no changes are made to Account B.

These states ensure that either the transaction completes successfully (committed) or the database is restored to its original state (aborted), maintaining consistency and preventing errors.


Next Article

Similar Reads