You are on page 1of 6

Database II

Database Concurrent Access

1
Muhammad Asghar Khan
Introduction

 Concurrency Control
• Process of managing simultaneous operations against a
database so that data integrity is maintained and operations
don’t interfere with each other in a multi-user environment
 Lost Update Problem
• The most common problem encountered when multiple
users attempt to update a database without concurrency
control is that of lost update
 Inconsistent Read / Dirty Read Problem
• Without concurrency problem occurs when one user reads
data that have been partially updated by another user
 There are two approaches to concurrency control
• Locking (Pessimistic Approach)
• Versioning (Optimistic Approach)
2
Locking (1/3)

 Locking
• Any data that are retrieved for updating must be locked, or
denied to other users until the update is completed or
aborted
• Locking Level (Granularity)
• Is the level of the database resource that is included with each lock
• Most commercial DBMS implements locks at one of the following
level
• Database
• Table
• Record Level (Row Level)
• Field Level (Column Level)
• Block or Page (Physical storage block/page containing a requested
record is blocked)

3
Locking (2/3)

 Types of Lock
• Shared Lock (S Lock / Read Lock)
• Allow other transactions to read (but not update) to record or data
• If S Lock is placed no user can place the exclusive lock
• Exclusive Lock (X Lock / Write Lock)
• Prevents another transaction from reading and therefore updating a
record until it is unlocked
• X Lock should be placed when a record is about to update
 Problem with Locks
• Locking may lead to the deadlock problem
• Deadlock is an bottleneck that result when two or more
transactions have locked a common resource, and each wait
for other resource to unlock that resource
4
Locking (3/3)

• Deadlocks can be resolved by


• Deadlock prevention
• User Program must lock all records they require at the begining of a
transaction (rather one at a time)

• The two phase locking protocol is used for locking

• In two phase locking once any lock obtained for the transaction is
released, no more locks may be obtained

• The two phases are: acquiring locks and releasing locks

• Deadlock Resolution
• Allows deadlocks to occur but builds mechanisms into the DBMS for
detecting and breaking the deadlocks

5
Versioning

 Versioning
• Each transaction is restricted to a view of the database as of
the time that transaction started, and when a transaction
modifies a record, DBMS creates a new record version
instead of overwriting the old record
Users Read/Make Changes to
(Transacti own copy
ons)
Update Changes according to Original Docs
timestamp, inform conflict transaction (Original Records)
user
Clerk
(DBMS) Makes Copy and Timestamps

Request
Docs Users private
copy (version)
(Records)

Clerk
Record Room (Database) (DBMS)6

You might also like