Understanding transaction states in Database Management Systems (DBMS) is crucial for maintaining data integrity and consistency in modern databases. Transactions play a pivotal role in ensuring that database operations are atomic, consistent, isolated, and durable (ACID).
Various transactions are carried out to alter the data in a database. There are various states that a transaction goes through over its existence.
This article aims to explore and examine various states of transaction in DBMS. We will cover the qualities of various states of transaction in DBMS.
What is a transaction states in DBMS?
A transaction is a series of operations or program units performed to complete a set of logical tasks whose execution may or may not change a database's contents. A transaction is separated into states to handle different circumstances, including system failure.
Generally, we perform two operations in a transaction.
Read Operations: It reads data from a database, stores it in a buffer in the main memory, and exit.
Write Operations: the changed data value is returned to the database using the buffer.
It shall be regarded as a single transaction from the start of the execution of a set of instructions to the finish of it.
The essential commands in a translation in DBMS are as follows:
COMMIT: The COMMIT command is only sent when every instruction has been correctly carried out.
ROLLBACK: If anything goes wrong during the transaction, the entire outcome should be reverted as if the transaction never occurred.
The states of transaction in DBMS control the processes determining whether a transaction will proceed or be terminated. These states of transaction in DBMS outline the transaction's current situation and provide details on how it will be handled going forward.
To control the process of transactions, they used to employ transaction logs. It is a record of activities taken by a Database management system that is used to ensure ACID properties in the phase of hardware crashes.
Every transaction in DBMS is a collection of two delimiters. Every transaction begins with delimiters marked begin transaction and ends with delimiters marked end transaction.
main()
{
begin transaction
} end transaction
Different Types of Transaction States in DBMS
Active State.
Partially Committed State.
Committed State.
Failed State.
Aborted State.
Terminated State.
Let’s discuss each one of them briefly.
Active State
It is the first stage of a transaction in DBMS. A transaction is said to be active if its instructions are being executed. One can perform operations such as INSERT or DELETE in the database, but the main memory buffer now contains all changes made by the transaction.
Partially Committed State
The transaction enters a partially committed state after the final instruction has completed execution. You might be amazed the final instruction has been completed. Then why it’s not in the Committed state? The main reason is all the changes made by transactions are still stored in the main memory buffer. That is why it is not regarded as completely committed.
Committed State
This can be considered as the completion of a transaction. All the changes stored in the buffer are transferred to the databases. In other words, all the instructions of a respective transaction are successfully completed, and changes are made in the database.
If a transaction reaches to committed state, then:
The modifications caused by the transaction cannot be undone.
The only option to reverse the modifications is to execute an additional transaction, which reverses operations in a different transaction.
Failed State
Suppose a transaction T is active or partially committed and experiences a failure that prevents it from continuing with the execution. Then, the transaction T is said to be in the failed state. Another reason can be the failure of the recovery system. T is considered to be in the failed state if any of the database recovery system's checks are unsuccessful.
Aborted State
Suppose any of the checks are unsuccessful and the transaction has reached a failed state. In that case, the database recovery mechanism will first try to recover the transaction and return it to its former consistent state. Otherwise, it will cancel the transaction or roll it back to restore consistency to the database.
The DBMS recovery system performs one of the two operations when a system reaches to aborted state:
Kill the transaction: The system will delete the transaction so it cannot affect other operations.
Re-start the transaction: The system, after some changes, again sends the operation to an active state.
Terminated State
This is the final stage of a transaction's life cycle. The transaction finally enters the terminated state when its life cycle is completed after having been in the committed or aborted stage.
Consider a banking application where a customer transfers money from one account to another. The transaction involves two main steps: deducting the amount from the sender's account and crediting it to the recipient's account. Let's examine the transaction states in this scenario:
Active State: The transaction starts in the active state when the customer initiates the transfer. It is currently executing and modifying the database.
Partially Committed State: After deducting the amount from the sender's account, the transaction enters the partially committed state. At this point, it has made all modifications to the database but has not yet been confirmed.
Committed State: Once the amount is successfully credited to the recipient's account, the transaction enters the committed state. All changes made by the transaction are now permanently saved in the database, and the transaction is considered successful.
Aborted State: If an error occurs during the transaction process, such as insufficient funds or a database failure, the transaction may enter the aborted state. In this state, any changes made by the transaction are rolled back, and the database returns to its original state.
Frequently Asked Questions
What is a transaction in DBMS?
A transaction is a series of operations or program units performed to complete a set of logical tasks whose execution may or may not change a database's contents. If we are performing some read-write operations on any database, it can be considered a transaction in DBMS.
What are the states of transaction in DBMS?
The states of a transaction in DBMS are:
Active: Transaction is executing and modifying the database.
Partially Committed: Transaction has made all modifications but not yet confirmed.
Committed: Changes are permanently saved.
Aborted: Transaction is rolled back due to failure.
What are the transaction states in distributed system?
In distributed systems, transaction states include: Active, Partially Committed, Committed, and Aborted. These states indicate the progress and outcome of transactions across multiple nodes or components.
What are the 4 basic transactions?
The four basic transactions are: Read, Write, Commit, and Abort. These transactions define the fundamental operations performed on data within a database management system (DBMS).
What are the 2 major types of transactions?
The two major types of transactions are: Short Transactions and Long Transactions. Short transactions are brief and typically complete quickly, while long transactions involve extended periods and complex operations, often requiring persistence mechanisms like logging.
Conclusion
In this article, we extensively discussed states of transaction in DBMS. We discussed these states of transaction in DBMS, outlined the transaction's current situation, and provided details on how it will be handled going forward.
We hope this blog has helped you. We recommend you visit our articles on transactions in DBMS.