Deadlock in dbms

Deadlock in DBMS

A deadlock is a condition where two or more transactions are waiting indefinitely for one another to give up locks. Deadlock is said to be one of the most feared complications in DBMS as no task ever gets finished and is in waiting state forever.
For example: In the student table, transaction T1 holds a lock on some rows and needs to update some rows in the grade table. Simultaneously, transaction T2 holds locks on some rows in the grade table and needs to update the rows in the Student table held by Transaction T1.
Now, the main problem arises. Now Transaction T1 is waiting for T2 to release its lock and similarly, transaction T2 is waiting for T1 to release its lock. All activities come to a halt state and remain at a standstill. It will remain in a standstill until the DBMS detects the deadlock and aborts one of the transactions.

Deadlock in DBMS

Deadlock Avoidance

  • When a database is stuck in a deadlock state, then it is better to avoid the database rather than aborting or restating the database. This is a waste of time and resource.
  • Deadlock avoidance mechanism is used to detect any deadlock situation in advance. A method like "wait for graph" is used for detecting the deadlock situation but this method is suitable only for the smaller database. For the larger database, deadlock prevention method can be used.

Coffman Conditions:-

A deadlock will only occur if the four Coffman conditions hold true. These conditions are not necessarily mutually exclusive. They are:

Mutual Exclusion

There should be a resource that can only be held by one process at a time. In the diagram below, there is a single instance of resource R1 and it is held by process P1 only.

Hold and Wait

A process can hold multiple resources and still request more resources from other processes which are holding them. In the diagram given below, process P1 holds resources R1 and R2 and is requesting the resource R3 which is held by process P2.

No Preemption

A resource cannot be preempted from a process by force. A process can only release a resource voluntarily. In the diagram below, process P1 cannot preempt resource R3 from Process P2. It will only be released when P2 relinquishes it voluntarily after its execution is complete.

Circular Wait

A process is waiting for the resource held by the second process, which is waiting for the resource held by the third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular chain. For example: Process P1 is allocated resource R1 and it is requesting resource R2. Similarly, process P2 is allocated resource R2 and it is requesting resource R1. This forms a circular wait loop.
A process is waiting for the resource held by the second process, which is waiting for the resource held by the third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular chain. For example: Process P1 is allocated resource R1 and it is requesting resource R2. Similarly, process P2 is allocated resource R2 and it is requesting resource R1. This forms a circular wait loop.

Thank you viewers. this is published by soumy sinha...if u like then pls share with your friends...for more information follow our fb page.

Comments

Popular posts from this blog

Introduction of Digital computer

INTRODUCTION OF DBMS

Introduction to cache memory