When, why and how does a database encounter deadlock?
What is Deadlock condition in DBMS ?
87503-Dec-2019
Updated on 03-Dec-2019
Home / DeveloperSection / Forums / What is Deadlock condition in DBMS ?
When, why and how does a database encounter deadlock?
Anonymous User
03-Dec-2019Deadlock condition in DBMS
The deadlock is a condition where two or more transactions are waiting indefinitely for one another to give up locks. The Deadlock is said to be one of the most feared complications in DBMS as no task ever gets finished and is in waiting for state forever.
Example:-
Into the Employee table, transaction Tab1 holds a lock on some rows and needs to update some rows in the grade table. Simultaneously, transaction Tab2 holds locks on some rows in the grade table and needs to update the rows in the Employee table held by Transaction Tab1. And now, the main problem arises. This means the Transaction Tab1 is waiting for Tab2 to release its lock and similarly, transaction Tab2 is waiting for Tab1 to release its lock. Each activity comes to a halt state and remains at a standstill. That will remain in a standstill until the DBMS detects the deadlock and aborts one of the transactions.
Deadlock Detection
The resource scheduler can detect a deadlock as it keeps track of all the resources that are allocated to different processes. After a deadlock is detected, it can be resolved using the following methods:
Deadlock Avoidance
This is better to avoid a deadlock rather than take measures after the deadlock has occurred. Here the wait for the graph can be used for deadlock avoidance. That is however only useful for smaller databases as it can get quite complex in larger databases.
For the larger database, the deadlock prevention method can be used.