Instead of letting deadlocks form and then detecting and breaking them, deadlock prevention tries to stop deadlocks from ever happening by changing how transactions request and hold resources.
In DBMS, deadlock prevention works by ensuring that at least one of the four necessary conditions for deadlock is never satisfied.
Four Conditions for Deadlock (Recall)
A deadlock can occur only if these four conditions hold simultaneously:
Mutual exclusion
Some resources (like locks) cannot be shared; only one transaction can hold them at a time.
Hold and wait
A transaction can hold some resources while waiting for others.
No preemption
A transaction cannot be forced to release a resource before it chooses to.
Circular wait
There exists a cycle of transactions, each waiting for a resource held by the next.
Deadlock prevention schemes break one of these conditions so that the system can never enter a deadlock state.
Strategies for Deadlock Prevention
1. Breaking “Hold and Wait”
To prevent transactions from holding some resources while waiting for others:
All‑or‑nothing resource request:
A transaction must request all the resources it needs at once, before it starts executing.
If all cannot be granted immediately, the transaction waits or is denied, rather than proceeding with partial locks.
This stops circular waits from forming because no transaction can hold one resource and wait for another.
Disadvantage:
Transactions may wait long for many resources, or waste locks they don’t end up using.
2. Breaking “No Preemption”
Allow the system to preempt (force‑release) resources from a transaction:
If a transaction cannot get a required resource immediately, it releases all its current locks and restarts later.
Alternatively, the DBMS can force a transaction to release some locks when another transaction needs them.
This breaks the “no preemption” condition and avoids long‑lasting circular waits.
Disadvantage:
Frequent restarting can hurt performance and complicate application logic.
3. Breaking “Circular Wait”
Eliminate the possibility of circular waits by enforcing a global ordering of resources:
All resources (tables, pages, rows, etc.) are given a fixed order.
Transactions must request resources in that order only (for example, always request locks on Table X before Table Y).
Because every transaction follows the same order, cycles cannot form: if waits for , cannot wait back for in the same way.
Disadvantage:
Applications must be designed to respect the lock order, which can be restrictive.
4. Breaking “Mutual Exclusion” (Rarely Used)
In theory, deadlocks could be prevented by removing mutual exclusion (allowing shared access where possible), but in DBMS this is limited:
Many locks must be exclusive (for writes) to preserve correctness.
So this condition is usually not broken; instead, prevention focuses on the other three.
Why Deadlock Prevention Matters
It is a proactive approach: deadlocks are avoided, not reacted to.
It can reduce or even eliminate the need for deadlock detection and abort mechanisms.
It trades some restrictiveness and overhead (for example, ordering locks or requesting all at once) for stronger safety.
For beginners, deadlock prevention is like imposing rules before the game starts so that no player can get into a circular deadlock situation.
Summary
Deadlock prevention in DBMS is the technique of stopping deadlocks by ensuring that at least one of the four necessary conditions (mutual exclusion, hold and wait, no preemption, circular wait) is never satisfied. Common strategies include requiring all resources upfront, allowing preemption, and enforcing a global lock order. While these methods prevent deadlocks, they also add restrictions and overhead, so DBMS often combines prevention with detection and avoidance in practice.