Deadlock Detection and Recovery in DBMS

A deadlock is said to occur when there is a circular chain of transactions, each waiting for the release of a data item held by the next transactions in the chain. A deadlock would occur under the following four conditions:

1. A data item can be accessed by only one transaction at a time. Another transaction can’t use a data item unless it is released by the transaction which locked it.

2. The transaction which requires a data item continues to wait for its release by the other transaction which locked it.

3. There is no provision for the preemption of data items. It means that a high-priority transaction is allowed to have a data item if it is being locked by a lower-priority transaction.

4. A circular wait condition is explained below:

Deadlock Detection :

The presence of a cycle in the wait-for-graph is the reason for a deadlock to occur. So, a deadlock can be detected by examining the wait-for-graph. If a cycle is detected in the graph, it is inferred that a deadlock has occurred.

Deadlock Recovery :

To recover from deadlock, the cycle in the wait-for-graph must be broken. The cycles can be broken by performing a rollback operation on one of the transactions forming the cycle.