Last Updated : 02 Aug, 2025
A lock in DBMS controls concurrent access, allowing only one transaction to use a data item at a time. This ensures data integrity and prevents issues like lost updates or dirty reads during simultaneous transactions.
Lock Based Protocols in DBMS ensure that a transaction cannot read or write data until it gets the necessary lock. Here's how they work:
Rules of LockingRead more about Types of Locks.
The basic rules for Locking are given below:
Read Lock (or) Shared Lock(S)
Write Lock (or) Exclusive Lock (X)
Concurrency Control Protocols are the methods used to manage multiple transactions happening at the same time. They ensure that transactions are executed safely without interfering with each other, maintaining the accuracy and consistency of the database.
These protocols prevent issues like data conflicts, lost updates or inconsistent data by controlling how transactions access and modify data.
Types of Lock-Based Protocols 1. Simplistic Lock ProtocolIt is the simplest method for locking data during a transaction. Simple lock-based protocols enable all transactions to obtain a lock on the data before inserting, deleting, or updating it. It will unlock the data item once the transaction is completed.
Example: Consider a database with a single data item X = 10
.
Transactions:
X
.X
.This example shows how simplistic lock protocols handle concurrency but do not prevent problems like deadlocks or limits concurrency.
2. Pre-Claiming Lock ProtocolThe Pre-Claiming Lock Protocol avoids deadlocks by requiring a transaction to request all needed locks before it starts. It runs only if all locks are granted; otherwise, it waits or rolls back.
Example: Consider two transactions T1 and T2 and two data items, X
and Y
:
Transaction T1 declares that it needs:
X
.Y
.Since both locks are available, the system grants them. T1 starts execution: It updates X.
It reads the value of Y
.
While T1 is executing, Transaction T2 declares that it needs: However, since T1 already holds a write lock on X
, T2's request is denied. T2 must wait until T1 completes its operations and releases the locks. A read lock on X
Once T1 finishes, it releases the locks on X
and Y
. The system now grants the read lock on X
to T2, allowing it to proceed.
This method is simple but may lead to inefficiency in systems with a high number of transactions.
A transaction is said to follow the Two-Phase Locking protocol if Locking and Unlocking can be done in two phases :
4. Strict Two-Phase Locking ProtocolFor more detail refer the article Two-phase locking (2PL).
Strict Two-Phase Locking requires that in addition to the 2-PL all Exclusive(X) locks held by the transaction be released until after the Transaction Commits.
Problem With Simple LockingFor more details refer the article Strict Two-Phase Locking Protocol.
Consider the Partial Schedule:
S.No T1 T2 1 lock-X(B) 2 read(B) 3 B:=B-50 4 write(B) 5 lock-S(A) 6 read(A) 7 lock-S(B) 8 lock-X(A) 9 ...... ...... 1. DeadlockIn the given execution scenario, T1 holds an exclusive lock on B
, while T2 holds a shared lock on A
. At Statement 7, T2 requests a lock on B
, and at Statement 8, T1 requests a lock on A
. This situation creates a deadlock, as both transactions are waiting for resources held by the other, preventing either from proceeding with their execution.
Starvation is also possible if concurrency control manager is badly designed. For example: A transaction may be waiting for an X-lock on an item, while a sequence of other transactions request and are granted an S-lock on the same item. This may be avoided if the concurrency control manager is properly designed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4