Home » DBMS

Locking protocols and its types in DBMS

In this article, we are going to discuss the different types of locking protocols.
Submitted by Bharti Parmar, on November 08, 2018

Locking Protocol in DBMS

The protocol utilizes locks, applied by a transaction to data, which may block (interpreted as signals to stop) other transactions from accessing the same data during the transaction's life.

Types of locking protocols

  1. Simple locking
  2. 2-Phase Locking
    1. Simple 2-phase locking
    2. Conservative 2-Phase locking
    3. Strict 2-phase locking
    4. Rigorous 2-phase locking
  3. Graph-based locks

1) Simple locking

  • If the first transaction is a shared lock, then the second transaction is to use a shared lock.
  • If the first lock is an exclusive lock, then no lock use in the second transaction.

Note: Simple locking achieves consistency means infinite waiting and sometimes it creates a problem.

2) 2-Phase lock

It is used to overcome the disadvantage of the simple lock. In the 2-phase locking, there are two phases are growing phase and shrinking phase. 2-phase ensures serializability.

Growing phase: A transaction may obtain locks but not release any locks.

Shrinking phase: A transaction may release lock but may not obtain new locks.

a) Simple 2-phase locking: Once a transaction releases a lock it enters in shrinking phase and in shrinking phase it cannot issue any more locks.

Advantage:

  • Less resource utilization.

Disadvantage:

  • Deadlock present.

Note: The final point of lock-in schedule of transaction called lock point of transaction. We denote conversion from shared to an exclusive mode called upgrade and its opposite conversion from exclusive to shared mode is called downgrade.

b) Conservative 2-phase locking: The lock of the entire data item that we need before the transaction starts.

Advantage:

  • No waiting for the data item
  • No deadlock create

Disadvantage:

  • Practically data implementation is difficult

c) Strict 2-phase locking: Transaction does not release any of the exclusive locks until after its commit or abort.

Advantage:

  • No dirty read problem
  • Proper lock

Disadvantage:

  • Deadlock create

d) Rigorous 2-phase locking: Transaction "t" does not release any of its locks until after it commits or aborts. All lock release at the same time no lock release first or last.

3) Graph-based protocol

It follows 6 rules:

  • It uses the only exclusive lock.
  • The first lock can be acquired on any data item.
  • Subsequent locks are allowed only if the parent is locked.
  • Unlock at any point.
  • Each data item can be accessed at most once.
  • Relocking by the same transaction is not allowed.

Advantage:

  • No rollback
  • No deadlock
  • Less waiting time

Disadvantage:

  • Prior knowledge of data
  • Unnecessary lock

Conclusion:

In this article, we have learned all the types of locking protocols and its advantage and disadvantage. In the next article, we gather more about DBMS. Stay tuned for the next article. Have a nice day! Happy Learning!






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.