0% found this document useful (0 votes)
48 views

Deadlock-Handling-in-DBMS

Uploaded by

rrajashrideepa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Deadlock-Handling-in-DBMS

Uploaded by

rrajashrideepa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Deadlock Handling in DBMS

A deadlock occurs when two or more transactions in a database system


are blocked, each waiting for the other to release a resource it needs.

RR by Rajashri Rajan
Understanding Deadlocks
Deadlock Conditions Mutual Exclusion Hold and Wait No Preemption
Deadlock occurs when four Only one transaction can A transaction holds at least Resources cannot be
necessary conditions are access a resource at a time. one resource and requests forcibly taken from a
met simultaneously. another resource currently transaction.
held by another
transaction.
Causes of Deadlocks
Concurrency Resource Contention
When multiple transactions When two or more transactions
access and modify the same request the same resource
data concurrently. simultaneously.

Inconsistent Data Access


Transactions accessing data in different orders, leading to blocking
situations.
Deadlock Detection Techniques

Wait-for Graph Timeout Rollback


Tracks dependencies between Transactions are aborted if they exceed Transactions are rolled back to a
transactions and identifies cycles, a predetermined time limit, preventing consistent state, releasing resources
indicating deadlocks. long-lasting deadlocks. and resolving the deadlock.
Deadlock Prevention
Strategies
1 Transactions acquire all required resources before starting.

2 Transactions request resources in a predefined order,


eliminating circular dependencies.

3 Prevents transactions from holding resources while waiting


for others.
Deadlock Avoidance Algorithms

Resource Ordering
1 Transactions request resources in a specific order.

Wait-for Graph Analysis


2
Predicts potential deadlocks based on resource allocation.

Safe State Analysis


3 Ensures that there is always a way to schedule transactions
to avoid deadlocks.
Deadlock Recovery
Approaches
Roll back one or more transactions involved in the deadlock.

Abort all transactions involved in the deadlock and restart


them later.
2

Wait for a transaction to release the resource, potentially


leading to prolonged delays.
3
Best Practices for Deadlock Handling

1 2
Minimize Lock Duration Avoid Unnecessary Locking
Hold locks for the shortest possible time. Lock only the required resources.

3 4
Consistent Resource Requests Monitor and Analyze
Acquire resources in a predictable order. Track deadlock occurrences and identify patterns.

You might also like