A deadlock occurs in a multi-user database environment when two or more transactions block each other indefinitely by each holding a resource the other needs. This results in a cycle of dependencies (circular wait) where no transaction can proceed.
For a large database, the deadlock prevention method is suitable. A deadlock can be prevented if the resources are allocated in such a way that a deadlock never occurs. The DBMS analyzes the operations whether they can create a deadlock situation or not, If they do, that transaction is never allowed to be executed.
Deadlock prevention mechanism proposes two schemes:
1. Wait-Die Scheme (Non-preemptive)
Older transactions are allowed to wait.
Younger transactions are killed (aborted and restarted) if they request a resource held by an older one
For example:
Consider two transaction- T1 = 10 and T2 = 20
If T1 (older) wants a resource held by T2 → T1 waits
If T2 (younger) wants a resource held by T1 → T2 dies and restarts
Prevents deadlock by not allowing a younger transaction to wait and form a wait cycle.
2. Wound-Wait Scheme (Preemptive)
Older transactions are aggressive (preemptive) and can force younger ones to abort.
Younger transactions must wait if they want a resource held by an older one.
For example:
Consider two transaction- T1 = 10 and T2 = 20
If T1 (older) wants a resource held by T2 → T2 is killed, T1 proceeds.
If T2 (younger) wants a resource held by T1 → T2 waits
Prevents deadlock by not allowing younger transactions to block older ones.
The following table lists the differences between Wait-Die and Wound-Wait scheme prevention schemes:
Wait - Die
Wound -Wait
It is based on a non-preemptive technique.
It is based on a preemptive technique.
In this, older transactions must wait for the younger one to release its data items.
In this, older transactions never wait for younger transactions.
The number of aborts and rollbacks is higher in these techniques.
In this, the number of aborts and rollback is lesser.