12-DBMS - Deadlock Handling
12-DBMS - Deadlock Handling
Akhilesh Arya
Deadlock in DBMS
• A deadlock is a condition where two or more
transactions are waiting indefinitely for one
another to give up locks
Deadlock Detection
• In a database, when a transaction waits
indefinitely to obtain a lock, then the
DBMS should detect whether the
transaction is involved in a deadlock or not
• The lock manager maintains a Wait for
the graph to detect the deadlock cycle in
the database
Wait for Graph
• This is the suitable method for deadlock detection
• In this method, a graph is created based on the
transaction and their lock
• If the created graph has a cycle or closed loop,
then there is a deadlock
Deadlock Handling
• There are 2 methods of deadlocking
handling:
– Deadlock Prevention
– Detection and Recovery
Deadlock Prevention
• Violate the properties such as mutual
exclusion, Hold and Wait, Preemption
and circular weight
• If none or one of the property is not
present in the transaction then
definitely we can prevent deadlock
Deadlock Recovery
• Wait- Die (Non- Preemptive)
– If TS(Ti) < TS(Tj) then Ti must wait (Ti is older)
– If TS(Ti) > TS(Tj) then Ti rollback (Die)
• Wound- Wait (Preemptive)
– If TS(Ti) > TS(Tj) then Ti can wait (Ti is yonger)
– If TS(Ti) < TS(Tj) then Tj rollback (Die)