EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

Lock Based Protocols in DBMS

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » Database Management Tutorial » Lock Based Protocols in DBMS

Lock Based Protocols in DBMS

Introduction to Lock Based Protocols in DBMS

The DBMS houses data that can interact with one another and can be manipulated at any given instant. In a few scenarios, there is a possibility of more than one user trying to access a certain data item at the same time creating a concurrency. Thus, a need arises to deal with the said concurrency to handle the simultaneous execution of tractions among the multiple databases in the picture. One such method is termed as Lock Based Protocols. In this topic, we are going to learn about Lock Based Protocols in DBMS.

Lock Based Protocols eliminate the shortcomings caused by the concurrency access in DBMS by providing the required isolation to the tractions involved within the DBMS.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

This article tends to provide an insight on Lock Based Protocols in DBMS.

What is Lock Based Protocols in DBMS?

Hundreds of transactions happen each moment. Consider booking a movie ticket in your favorite cinemas, chances are two users will try to book the same seat unknowing to one another. A scenario like this, when dealt on a large scale, might affect the database consistency leading to the corruption of data. In order to avoid conflicts w.r.t the user access to read and write into the database, and to maintain consistency throughout the DBMS, each traction must be enforced in isolation. This task is achieved by implementing Lock Based Protocols in DBMS.

Lock based Protocols in simpler terms helps overcome the issues related to accessing the DBMS concurrently by locking the current transaction for only one user. The assumption or more like a requirement that is necessary for implementing Lock Based Protocol is that all the data items involved are accessed in a mutually exclusive manner i.e. when one traction is active by a user, no other traction is allowed access to update or modify that traction at the same time. As the name suggests, the Lock based protocols when in action, are required to acquire a lock to access the data items and release the lock when the said traction is completed.

Types of Locks in DBMS

The locking and unlocking of data items in Lock based Protocols in DBMS are implemented in 2 modes:

Popular Course in this category
Sale
SQL Training Program (7 Courses, 8+ Projects)7 Online Courses | 8 Hands-on Projects | 73+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,891 ratings)
Course Price

View Course

Related Courses
PL SQL Training (4 Courses, 2+ Projects)Oracle Training (14 Courses, 8+ Projects)
  • Shared Lock (lock-S)
  • Exclusive Lock (lock-X)

1. Shared Lock

Often represented as lock-S(), Shared Locks are basically the locks that grant Read-Only access to the data items associated with it. This means when a shared lock is implemented on a database, it can be READ by multiple users, however, none of the users reading the data items will be able to update it. In other words, there is no write access associated with Shared Lock. Since multiple users can read the data items simultaneously, more than one shared lock can be placed on them at a given time but for the shared lock to be placed, the data item must not have any other locks associated with it.

Example of shared Lock:

Example of shared Lock

Consider a transaction(T1) which requires only to read the data item value A. The following steps take place when lock protocol is applied to this traction

  1. T2 will acquire an exclusive lock on the data item A
  2. Read the current value of data item A
  3. Once the transaction is completed, the data item will be unlocked

2. Exclusive Lock

While Shared Lock allows Read-Only access, Exclusive Locks allow both Read and Write access on a data item present in the database. Often represented as lock-X(), Exclusive locks provide the privilege of reading and modifying the data as seen fit by a user. For the sake of security and consistency of the database, this process will be exclusive to the user using them and is not permitted to other users trying to access the same data item. Once the exclusive lock is placed, no other locks including the Shared lock can be placed on the same row or column until its unlocked.

Example of Exclusive Lock:

Example of Exclusive Lock

Consider a transaction(T2) which requires to update the data item value A. The following steps take place when lock protocol is applied to this traction

  1. T2 will acquire an exclusive lock on the data item A
  2. Read the current value of data item A
  3. Modify the data item as required. In the example illustrated, a value of 50 is subtracted from the data item A
  4. Write the updated value of the data item
  5. Once the transaction is completed, the data item will be unlocked.

Lock Compatibility Matrix

A keynote while applying the Lock based protocols in DBMS is that: any number of tractions can hold a Shared Lock while only one traction has a claim over Exclusive Lock since because shared lock is only reading the data and not performing any other actions whereas the exclusive lock is performing both read and write operations. This can be illustrated using a compatibility matrix like the one shown below:

Lock Compatibility Matrix

The figure illustrates that when two transactions are involved, and both attempt to only read a given data item, it is permitted and no conflict arises, but when one transaction attempts to write the data item and another one tries to read or write at the same time, conflict occurs resulting in a denied interaction.

Conversion between the locks is possible by the two methods listed below:

Upgrading: conversion from a read lock to write lock

Downgrading: conversion from a write lock to read lock

Problems associated with Simple locking:

  1. Data inconsistency between multiple transactions
  2. Deadlock, a situation where the transactions try to access lock on already locked data items
  3. No guarantee of serializability (i.e. execution of a concurrent transaction equivalent to that of a transaction executed serially)

Two Phase Locking (2PL)

The trivial requirement for a 2PL to exist is that the locking and unlocking of a transaction take place in either of the 2 phases i.e. Growing or Shrinking phase

Growing Phase: It is the phase where new locks can be acquired on the data items.

Shrinking phase: It is the phase where the existing locks on the data items are released.

The above phases in a DBMS are determined by something called a ‘Lock Point’. Lock point is the point where a transaction has achieved its final lock. It is also the point where the growing phase ends and the shrinking phase begins.

Lock Based Protocols in DBMS

Types of 2 Phase Locking (PL)

Here are the types of 2 phase locking mention below

1. Conservative 2PL

Conservative or Static 2PL when implied acquires all the locks before a transaction begins and releases the locks once the transaction is committed. This kind of 2 PL helps in overcoming problems related to cascading rollback and deadlocks.

2. Strict 2PL

In this type of 2PL, the exclusive (write) lock is released only after a transaction is committed, whereas a shared (read) lock can be released at regular intervals. Though Strict 2PL helps overcome the cascading rollback issues, it may also cause a bottleneck in some cases.

3. Strong strict or Rigorous 2PL

In this type of 2PL, both shared and exclusive locks are released only when the transaction is ended, i.e. when the transaction is committed or aborted. This kind of 2PL is used in practice today, promotes serializability and is simpler to implement due to the strictness involved w.r.t the implementation of the phase endings.

Conclusion

Concurrency control is essential in DBMS for handling the simultaneous execution of transactions among various databases. Lock Based Protocols being an essential member in the concurrency control technique enforces isolation among the transactions, preserve and maintain the reliability of the database, and resolve the conflicts of read-write and write-read operations. In addition to Lock based Protocols concurrency control can also be achieved via methodologies such as Timestamp Protocol, Mutilversion concurrency Protocol, and Validation Concurrency Protocols.

Recommended Articles

This is a guide to Lock Based Protocols in DBMS. Here we discuss what is Lock Based Protocols in DBMS and its types along with the examples and 2 Phase Locking. You may also look at the following articles to learn more –

  1. Types of DBMS
  2. Hashing in DBMS
  3. Normalization in DBMS
  4. Deadlock in DBMS
  5. Serializability in DBMS | Types with Examples

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Database Management Tutorial
  • DBMS
    • Introduction To DBMS
    • DBMS ER Diagram
    • What is DBMS?
    • DBMS join
    • DBMS Functions
    • Data Administrator in DBMS
    • DBMS Canonical Cover
    • DBMS Log-Based Recovery
    • DBMS Multivalued Dependency
    • Netezza Database
    • DBMS Concepts
    • DBMS Constraints
    • DBMS_Scheduler
    • B+ Tree in DBMS
    • DBMS_LOB
    • dbms entity
    • DBMS Foreign Key
    • DBMS Users
    • DBMS_Metadata.get_ddl
    • Relational Algebra in DBMS
    • DBMS Components
    • DBMS Features
    • DBMS Models
    • DBMS Relational Model
    • Hashing in DBMS
    • DBMS network model
    • Relationship in DBMS
    • ER Model in DBMS
    • Data Models in DBMS
    • Static Hashing in DBMS
    • Advantages of DBMS
    • dbms_output.put_line
    • DBMS Data Dictionary
    • dbms_xplan.display_cursor
    • Normal Forms in DBMS
    • DBMS helps achieve
    • DBMS 3 tier Architecture
    • Relational Calculus in DBMS
    • Serializability in DBMS
    • File Organization in DBMS
    • DBMS Transaction Processing
    • States of Transaction in DBMS
    • Functional Dependency in DBMS
    • Generalization in DBMS
    • Data Independence in DBMS
    • Lock Based Protocols in DBMS
    • Deadlock in DBMS
    • Integrity Constraints in DBMS
    • Concurrency Control in DBMS
    • Validation Based Protocol in DBMS
    • DBMS Locks
    • Normalization in DBMS
    • Transaction Property in DBMS
    • Specialization in DBMS
    • Aggregation in DBMS
    • Types of DBMS
  • DataBase Management
    • Text Data Mining
    • Roles of Database Management System in Industry
    • SQL Server Database Management Tools
    • Database administrator skills
    • Database Management Systems Advantages
    • Database Testing Interview Questions
    • Data Administrator
    • Database Administrator
    • Database Management Software
    • DataStage
    • Types of Database Models
    • Types of Database
    • Hierarchical Database Model
    • Relational Database
    • Relational Database Advantages
    • Operational Database
    • What is RDBMS?
    • What is DB2?
    • Data Masking Tools
    • Database Security
    • Data Replication
    • Bitmap Indexing
    • Second Normal Form
    • Third Normal Form
    • Fourth Normal Form
    • Data Definition Language
    • Data Manipulation Language
    • Data Control Language
    • Transaction Control Language
    • Conceptual Data Model
    • Entity-Relationship Model
    • Relational Database Model
    • Sequential File Organization
    • Checkpoint in DBMS
    • Teradata Create Table
    • Centralized Database
    • Data Storage in Database
    • Thomas write Rule
    • DBA Interview Questions
    • What is JDBC?
    • jdbc hive
    • Apriori Algorithm
    • JDBC Architecture
    • JDBC Interview Questions
    • Wildcard Characters
    • Distributed Database System
    • Multidimensional Database
  • PL/SQL
    • What is PL/SQL?
    • Careers in PL/SQL
    • PLSQL procedure
    • PL/SQL Exception
    • PL/SQL LIKE
    • PL/SQL Raise Exception
    • PLSQL rowtype
    • PLSQL? bind variables
    • PL/SQL Record
    • PL/SQL WITH
    • PL/SQL bulk collect
    • PL/SQL Block Structure
    • PL/SQL else if
    • PL/SQL nvl2
    • PL/SQL Package
    • PL/SQL exists
    • PL/SQL instr
    • PL/SQL listagg
    • PL/ SQL Formatter
    • PLSQLlength
    • PL/SQL Commands
    • PL/SQL Data Types
    • CASE statement in PL/SQL
    • PL/SQL IF Statement
    • Loops in PL/SQL
    • PL/SQL Add Column
    • For Loop in PLSQL
    • PL/SQL Cursor Loop
    • PLSQL Array
    • Cursors in PL/SQL
    • PL/SQL FOR Loop Cursor
    • PL/SQL Queries
    • PL/SQL SELECT INTO
    • PL/SQL TO_CHAR
    • PL/SQL UNION
    • PL/SQL NOT EQUAL
    • PL/SQL varray
    • PL/SQL Concatenate
    • PL/SQL UPDATE
    • PL/SQL TRIM
    • PL/SQL GROUP BY
    • PL/SQL GOTO
    • PL/SQL Date Functions
    • PL/ SQL having
    • PL/SQL to_DATE
    • PL/SQL NVL
    • PLSQL format date
    • PLSQL mod
    • PLSQL round
    • PL/SQL Boolean
    • PL/SQL exit
    • PL/SQL DECODE
    • PL/SQL ROWNUM
    • PLSQL?pivot
    • PLSQL string functions
    • PL/SQL Block
    • PL/SQL Function
    • PL/SQL Unwrapper
    • PL/SQL Table
    • PL/SQL ALTER TABLE
    • PLSQL execute immediate
    • Triggers in PL/SQL
    • PL/SQL Collections
    • PL/SQL stored procedure
    • PL/SQL Anonymous Block
    • PLSQL Interview Questions
  • TSQL Basic
    • TSQL
    • What is T-SQL
    • T-SQL Commands
    • T-SQL String Functions
    • TSQL Interview Questions
  • MariaDB
    • MariaDB Versions
    • MariaDB?list users
    • MariaDB Commands
    • MariaDB odbc
    • MariaDB Workbench
    • MariaDB for windows
    • MariaDB Server
    • MariaDB? Data Types
    • MariaDB?boolean
    • MariaDB phpMyAdmin
    • MariaDB Mysqldump
    • MariaDB Java Connector
    • MariaDB insert
    • MariaDB UPDATE
    • MariaDB? rename column
    • MariaDB AUTO_INCREMENT
    • MariaDB Timezone
    • MariaDB GROUP_CONCAT
    • MariaDB wait_timeout
    • MariaDB MaxScale
    • MariaDB? with
    • MariaDB? create?table
    • MariaDB? SHOW TABLES
    • MariaDB alter table
    • MariaDB List Tables
    • MariaDB JSON Functions
    • MariaDB Foreign Key
    • MariaDB? trigger
    • MariaDB Grant All Privileges
    • MariaDB Select Database
    • MariaDB? create database
    • MariaDB Delete Database
    • MariaDB List Databases
    • MariaDB Functions
    • MariaDB? TIMESTAMP
    • MariaDB create user
    • MariaDB add user
    • MariaDB show users
    • MariaDB Delete User
    • MariaDB? change user password
    • MariaDB? change root password
    • MariaDB reset root password
    • MariaDB IF
    • MariaDB bind-address
    • MariaDB Transaction
    • MariaDB Cluster
    • MariaDB Logs
    • MariaDB Encryption
    • MariaDB? backup
    • MariaDB Replication
    • MariaDB max_allowed_packet
    • MariaDB? performance tuning
    • MariaDB export database
    • MariaDB? import SQL
  • SQLite
    • What is SQLite
    • SQLite Commands
    • SQLite Data Types
    • SQLite COUNT
    • SQLite Boolean
    • SQLite autoincrement
    • SQLite select
    • SQLite? Bulk Insert
    • SQLite? add column
    • SQLite? concat
    • SQLite BETWEEN
    • SQLite group by
    • SQLite CASE
    • SQLite group_concat
    • SQLite array
    • SQLite? enum
    • SQLite sum
    • SQLite create table
    • SQLite Alter Table
    • SQLite Create Database
    • SQLite Delete
    • SQLite connection string
    • SQLite Database
    • SQLite Describe Table
    • SQLite Show Tables
    • SQLite exit
    • SQLite create index
    • SQLite foreign key
    • SQLite Stored Procedures
    • SQLite Extension
  • DB2
    • DB2? current date
    • DB2 purescale
    • DB2 backup
    • DB2 restore
    • DB2 C Express
    • DB2 Version
    • DB2? Architecture
    • DB2? Data Types
    • DB2? load
    • DB2? order by
    • DB2 date
    • DB2 NVL
    • DB2? update
    • DB2 warehouse
    • DB2 grant
    • DB2 database
    • DB2 VARCHAR
    • DB2? INSERT
    • DB2 LISTAGG
    • DB2 LIKE
    • DB2 TRUNCATE TABLE
    • DB2 LIST TABLES
    • DB2 between
    • DB2? current timestamp
    • DB2? length
    • DB2? bind
    • DB2 limit rows
    • DB2? export
    • DB2 with
    • DB2 Create Table
    • DB2 case statement
    • DB2 CAST
    • DB2 Functions
    • DB2 Date Functions
    • DB2? row_number
    • DB2 trim
    • DB2? Translate
    • DB2 UNION
    • DB2 timestamp
    • DB2? TIMESTAMPDIFF
    • DB2? replace
    • DB2 merge
    • DB2 COALESCE
    • DB2 ISNULL
    • DB2? explain
    • DB2 Join
    • DB2 alter column
    • DB2 rename column
    • DB2? Describe Table
    • DB2? rename table
    • DB2 List Databases
    • DB2 LUW
    • DB2 Query
    • DB2 GROUP BY
    • DB2 TO_DATE
    • View Serializability in DBMS
    • MariaDB Join
    • MariaDB JSON
    • MariaDB? show databases
    • Dataset Normalization
    • MariaDB Max Connections
    • jdbc connection
    • MariaDB GUI

Related Courses

SQL Certification Course

PL/SQL Certification Course

Oracle Certification Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Special Offer - SQL Certification Course Learn More