EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials DBMS Tutorial Deadlock in DBMS
Secondary Sidebar
DBMS Tutorial
  • DBMS
    • What is DBMS?
    • Introduction To DBMS
    • DBMS ER Diagram
    • DBMS_RANDOM
    • DBMS_XPLAN
    • DBMS join
    • DBMS Functions
    • Data Administrator in DBMS
    • Checkpoint in DBMS
    • DBMS Table
    • Mapping Constraints in DBMS
    • DBMS Canonical Cover
    • DBMS Log-Based Recovery
    • DBMS Multivalued Dependency
    • View Serializability in DBMS
    • DBMS Concepts
    • DBMS Constraints
    • DBMS_Scheduler
    • B+ Tree in DBMS
    • DBMS_LOB
    • dbms entity
    • DBMS Foreign Key
    • DBMS Users
    • DBMS_Metadata.get_ddl
    • Relational Algebra in DBMS
    • DBMS Components
    • DBMS Features
    • DBMS Models
    • DBMS Relational Model
    • Hashing in DBMS
    • DBMS network model
    • Relationship in DBMS
    • ER Model in DBMS
    • Data Models in DBMS
    • Static Hashing in DBMS
    • Advantages of DBMS
    • dbms_output.put_line
    • DBMS Data Dictionary
    • dbms_xplan.display_cursor
    • Normal Forms in DBMS
    • DBMS helps achieve
    • DBMS 3 tier Architecture
    • Relational Calculus in DBMS
    • Serializability in DBMS
    • File Organization in DBMS
    • DBMS Transaction Processing
    • States of Transaction in DBMS
    • Functional Dependency in DBMS
    • Generalization in DBMS
    • Data Independence in DBMS
    • Lock Based Protocols in DBMS
    • Deadlock in DBMS
    • Integrity Constraints in DBMS
    • Concurrency Control in DBMS
    • Validation Based Protocol in DBMS
    • DBMS Locks
    • Normalization in DBMS
    • Transaction Property in DBMS
    • Specialization in DBMS
    • Aggregation in DBMS
    • Types of DBMS

Deadlock in DBMS

By Priya PedamkarPriya Pedamkar

Deadlock in DBMS

What is Deadlock in DBMS?

A Deadlock in DBMS can be termed as the undesirable condition which appears when a process waits for a resource indefinitely whereas this resource is detained by another process. In order to understand the deadlock concept better, let us consider a transaction T1 which has a lock on a few rows in the table Employee and it requires to update some rows in another table Salary. Also, there exists another transaction T2 that has a lock on the table Salary and it also requires updating a few rows in the Employee table which already is held by the transaction T1. In this situation both the transactions wait for each other to release the lock and the processes end up waiting for each other to release the resources. As a result of the above scenario, none of the tasks gets completed and this is known as deadlock.

Working of Deadlock in DBMS

In the state of deadlock, no tasks get completed and they remain in the state of waiting for an indefinite time. We can understand the situation better by the below diagram. Resource 2 is held by Process 1 and Process 1 needs Resource 1. Similarly, Resource 1 is held by Process 2 and Process 2 needs Resource 2. Deadlock should be avoided as because of it the entire system comes to rest.

Working of Deadlock in DBMS

There are few conditions in which a deadlock may arise. One of the conditions is where a process waits for a resource that is held by a second process and this second process is awaiting the third and as we go on, the last process is awaiting the first which makes the waiting a circular chain. Another condition can be termed as Hold and Wait as the process which holds one resource can ask for extra resources that are held by the other processes.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Another condition for the occurrence of a deadlock is that a resource cannot be dynamically taken from a process because the process is only capable of freeing the resource held by it. A deadlock may arise if at least one resource must exist which at a time cannot be used by more than one resource and this condition can be called mutual exclusion. The handling of deadlock is costly and it is better if we can prevent it rather than handling it.

How to detect Deadlock in DBMS?

The deadlock can be detected by the resource scheduler who checks all the resources allocated to the different processes. The deadlock should be avoided instead of terminating and restarting the transaction so that both resources as well time is not wasted. One of the methods for detecting deadlock is Wait-For-Graph which is suitable for smaller databases.

Wait-For-Graph

A graph is created based on the transactions and locks on the resource in this method. A deadlock occurs if the graph which is created has a closed-loop. For all transactions waiting the resources are maintained by DBMS and also are checked to see if there is any closed loop. Let us consider two transactions T1 and T2 where T1 requests for a resource held by T2. The wait-for-graph in this scenario draws an arrow from T1 to T2 and when the resource is released by T2, the arrow gets deleted. For example, T1 requests for a lock X on a resource, which is held by T2, a directed edge is created from T1 to T2. When T2 releases the resource X, the edge T1 locks the resource and the directed edge between T1 and T2 is dropped.

Wait For Graph

How to prevent Deadlock in DBMS?

In DBMS, all the operations are analyzed and inspected by it to find if there is any possibility of occurrence of deadlock and in case of the possibility of deadlock, the transaction is not allowed to be processed. Primarily, the timestamp at which the transactions have begun is examined by the DMBS and based on this the transactions are ordered. The deadlock can be prevented by using schemes that use the timestamp of the transactions to calculate the occurrence of deadlock.

1. Wait- Die Scheme

In this scheme, when a transaction requests for the resource which is already held by another transaction, then the timestamps of the transactions are scanned by the DBMS and the older transaction waits till the resource becomes available. Let us consider two transactions T1 and T2 and the timestamp of the transaction be denoted by TS. If T1 requests for resources held by T2 and a lock exists on T2 by some other transaction,

Below are the steps followed:

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,408 ratings)
  • Whether TS(T1) < TS(T2) is examined, and if T1 is the older transaction between T1 and T2 and some resource is held by the transaction T2, then it permits T1 to await the resource to be available for execution.
  • If T1 is the older transaction that has held some resource and T2 is waiting for the resource held by T1, then T2 gets killed and later it will be restarted with the same timestamp but with a random delay.

2. Wound Wait Scheme

In this scheme, if T1 is the older transaction in between transactions T1 and T2, and when T2 requests for the resource which is held by the transaction T1, then the younger transaction i.e. T2 waits until T1 releases the resource. But when the resource held by the younger transaction T2 is requested by the older transaction T1, T2 is forced by T1 to kill the transaction in order to release the resource held by it and afterward T2 is restarted with a delay but with the same timestamp.

Conclusion

Deadlock handling is costly as well as time-consuming. So DBMS inspects the transactions to determine any possibility of any deadlock to occur and effectively removes such scenarios by not letting the particular transaction to be executed. Deadlock is an important concept for building a robust system.

Recommended Articles

This is a guide to Deadlock in DBMS. Here we discuss how to detect Deadlock in DBMS and the working of Deadlock with respective diagrams. You can also go through our other related articles to learn more–

  1. Hashing in DBMS
  2. Data Models in DBMS
  3. DBMS Architecture
  4. Working of Specialization in DBMS
  5. Guide to Aggregation in DBMS
  6. Serializability in DBMS | Types with Examples
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more