×

Deadlock in DBMS

Deadlock in DBMS

A deadlock is an unwanted condition in which two or more transaction are waiting indefinitely for one another to give up locks. It is said to be one of the most feared complications in database management system as no operation ever gets completed and is in waiting state forever.          


Example  

To understand the concept of deadlock, take an example:In the account table, transaction T1 holds a lock on some rows and needs to update some rows in the order table. Simultaneously, transaction T2 holds a lock on some rows in the order table but needs to update the rows in the account table held by Transaction T1.

Now, the main problem arises. Transaction T1 cannot complete its execution because it is waiting for transaction T2 to release its lock. And similarly, transaction T2 is waiting for transaction T1 to release its lock. Due to this, all activities come to a halt state and remains at a standstill forever until the database management system (DBMS) detects the deadlock and aborts one of the transactions.

Deadlock Avoidance

When a database is stuck in the deadlock condition, then it is always better to avoid the database rather than restarting or aborting the database.

The deadlock avoidance method is used to detect and deadlock situation in advance, and this mechanism is suitable for smaller databases. For the larger databases, deadlock prevention mechanism can be used.

Deadlock Detection

When a transaction waits indefinitely to obtain a lock in the database, then the database management system (DBMS) should detect whether the transaction is involved in a deadlock condition or not. To detect the deadlock cycle in the database lock manager maintains the wait-for-graph.


Wait-For Graph

  • Wait-for graph is one of the suitable methods for deadlock detection, and it is suitable for smaller databases. In this method,
  • graph can be created on the basis of a transaction and their locks on the resources. If the created graph contains a loop or a cycle, then there exists a deadlock situation.
  • For the above scenario, the wait-For graph is shown below:


Deadlock Prevention

  • Deadlock prevention is  method which is suitable for large databases. If the resources are allocated in such a way that the deadlock situation never occurs, then a deadlock can be prevented.   
  • The database management system (DBMS) analyses the operation of a transaction, whether they can create a deadlock condition or not. If they create a situation, then DBMS never allowed that transactions to execution.  

Deadlock prevention mechanism proposes the following two different schemes:   

1. Wait-Die Scheme
2. Wound-Wait Scheme

Wait-Die Scheme

The wait–die scheme is a nonpreemptive technique. When transaction Ti requests a data item which is currently held by Tj. T

hen Ti transaction is allowed to wait only if the timestamp of Ti transaction is smaller than that of transaction Tj ( i.e., Ti is older than Tj). Otherwise, Ti is rolled back (dies).

 
For example, suppose that transactions T14, T15, and T16 have timestamps 5, 10, and 15, respectively. If transaction T14 requests a data item held by T15, then T14 will wait for execution. If T24 transaction requests a data item held by T15, then T16 will be rolled back. 

Wound-Wait Scheme

The wound–wait scheme is a preemptive technique. When Ti transaction requests a data item which is currently held by Tj, Ti is allowed to wait only if it has a timestamp larger than that of Tj (that is, Ti is younger than Tj). Otherwise, Tj transaction is rolled back(Tj is wounded by Ti). 


Related Topics

Types of DBMS

Database Management System A software that is programmed to enable the user to create and maintain a database. Using DBMS, we can implement create, read, update and delete operations on the...

4 minutes read.

Checkpoint in DBMS

A checkpoint in DBMS is used to define a point of the transaction that is in a consistent state and then all the transactions will be in the committed state...

4 minutes read.

Types of Data Abstraction in DBMS

What Is Data Abstraction? To ship an email, you want to know the address. But to send the email, you don't need to see where the email is physically stored. You...

6 minutes read.

What is a Cloud Database

Cloud computing is the process of commoditizing data storage and processing time using standardized technologies. Cloud databases are databases that are hosted on cloud computing platforms such as Salesforce, GoGrid,...

4 minutes read.

Three Schema Architecture of DBMS

The three schema architecture describes how the data is represented or viewed by the user in the database. This architecture is also known as three-level architecture and is sometimes called...

3 minutes read.

Difference between DBMS and RDBMS

Database Management System A DBMS is system software which is used to store and manage the data in the database. It was introduced in 1960 for storing the data or information. This system allows...

3 minutes read.

Advantages of B-Tree in DBMS

A self-balancing search tree is the B-Tree. It is assumed that everything is in the main memory in most other self-balancing search trees (such as AVL and Red-Black Trees). We must...

3 minutes read.

DBMS Languages

User can access, update, delete, and store data or information in the database using database languages. The following are the databases languages in the database management system: Data Definition Language Data Manipulation...

3 minutes read.

Database for library management system

The database can be considered the container where the data or information can be stored electronically in a computer system. Most mobile applications and websites run our day-to-day activities by...

5 minutes read.

3- Tier Architecture in DBMS

Three-tier architecture is an application software architecture that arranges the output into three parts or tiers that are:  the presentation tier, where the user interacts with the application; the application...

4 minutes read.

Difference between Dropbox and Amazon Drive

What is Dropbox? It is a file organising company that is owned by the American Company Dropbox Inc. Itsheadquarters is situated in San Francisco, California, U.S. Dropbox offers personal cloud, client...

3 minutes read.

Hashing in DBMS: Static and Dynamic

Hashing in DBMS: Hashing is the technique of the database management system, which directly finds the specific data location on the disk without using the concept of index structure. In the...

4 minutes read.

Components of an ER Diagram

An ER Diagram consists of the following components: Entity AttributesRelationships 1. Entity An entity may be an object, place, person, or an event which stores data in the database. In an entity-relationship diagram, an entity...

4 minutes read.

Difference between Relational and Non-Relational Databases

Databases have become an integral part of our lives, from powering big websites like Amazon and Netflix to everyday tasks like remembering our passwords. With such an indispensable role in...

7 minutes read.

Red-Black Tree Visualization in DBMS

Introduction to Red Black Tree A red-black tree is a self-balanced binary search tree with an extra bit per node, usually read as a color (red or black). The tree is...

4 minutes read.

ER Diagram for Banking System in DBMS

Entity Relationship Diagram Entity Relationship Diagrams, or ER Diagrams for short, are diagrams that show the relationships among entity sets that are stored in databases. Alternatively said, ER diagrams assist in...

3 minutes read.

Founder of DBMS

The first database management system was built to automate the business of the General Electric Company. It was built by a small group of programmers. The Integrated Data Store IDS...

4 minutes read.

What is RDBMS?

To discuss the Relational Database Management System, there are some terms and concepts you need to know. Database Any collection of related information is called a database. The phone book is...

5 minutes read.

Components of DBMS

The database management system (DBMS) represents an essential tool for processing data within effectively structured structures. The database management system consists of important components that work together to maintain the...

6 minutes read.

DBMS Tutorial | Database Management System

Database Management System (DBMS) tutorial is all about managing and maintaining the data effectively. Our DBMS tutorial is designed for beginners as well as professionals. What is Data? Data is a real-world...

5 minutes read.