SlideShare a Scribd company logo
LOCKING AND CONCURRENCY
Multi-user concurrent and consistent access to the database
structure is the biggest challenge.
Locking and Concurrency ensures that every user can read and
change the data consistently.
Oracle is rather good at it.
LOCKING
A lock is a mechanism used to arrange concurrent access to a shared resource.
Oracle locks table data at the row level, but it also uses
locks at many other levels to provide concurrent
access to various resources.
LOCKING ISSUES
Lock mechanism have to some issues. It is caused by bad design.
+Lost Updates
+Pessimistic Locking
+Optimistic Locking
+Blocking
-Blockend Inserts
-Blocked Updates and Deletes
-Deadlocks
-Lock Escalation
Lost Updates Deadlock
Types of Lock
DML Lock : DML locks guarantee the integrity of the data accessed by multiple users
at the same time.
- TX(Transaction) Locks : A TX lock is acquired when a transaction initiates its
first change, and is held until the transaction performs a COMMIT or
ROLLBACK.
- TM Locks : These locks are used to ensure that the structure of a table is not
altered while you are modifying its contents.
DDL Locks : DDL locks are automatically placed against objects during a DDL
operation to protect them from changes by other sessions.
DDL locks are held for the duration of the DDL statement, and are released
immediately afterwards.
There are 3 kinds of DDL LOCK.
- Exclusive DDL Locks
- Share DDL Locks
- Breakable Parse Locks
Latches and Internal Locks : Latches and enqueues are lightweight serialization devices
used to coordinate multi-user access to shared data structures, objects and files.
Latches are locks that are held for extremely short periods of time, for example the t
me it takes to modify an in memory data structure.
Manual Locking
The SELECT...FOR UPDATE statement is the predominant method of manually
locking data.
We can also manually lock data using the LOCK TABLE statement.
You might use the LOCK TABLE IN EXCLUSIVE MODE statement if you were
writing a large batch update that would affect most of the rows in a given table, and
you wanted to be sure that no one would ʹblockʹ you.
What is Concurrency Control ?
Concurrency controls are the collection of functions that the database provides in
order to allow many people to access and modify data simultaneously.
The lock mechanism affects concurrency.
Oracle's multi-versioning model for read consistency is always applied at the statement
level and can also be applied at the transaction level.
TRANSACTION ISOLATION LEVEL
The SQL92 standard defines four levels of transaction isolation, with different
possible outcomes for the same transaction scenario.
These isolation levels are defined in terms of three phenomena that are either
permitted or not at a given isolation level:
- Dirty Read
- Non-Repeatable Read
- Phantom Read
Isolation Levels
Repeatable Read : Data that has been updated but has not yet been initialized cannot
be read or updated by other transactions until it has been committed.
Read Committed : Data that is being updated by other transactions cannot be read
until the update process is complete.
Read Uncommitted : Data that is being updated by other transactions but that has not
yet been updated can be read.
Serializable : This is generally considered the most restrictive level of transaction
isolation, but provides the highest degree of isolation.
Serializable transactions see only those changes that were committed at the time the
transaction began, plus those changes made by the transaction itself through INSERT,
UPDATE, and DELETE statements. Serializable transactions do not experience
nonrepeatable reads or phantoms.
Locking and concurrency

More Related Content

Similar to Locking and concurrency

Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
Meghaj Mallick
 
Managing Memory & Locks - Series 2 Transactions & Lock management
Managing  Memory & Locks - Series 2 Transactions & Lock managementManaging  Memory & Locks - Series 2 Transactions & Lock management
Managing Memory & Locks - Series 2 Transactions & Lock management
DAGEOP LTD
 
Dbms voc 5 unit
Dbms voc 5 unitDbms voc 5 unit
Dbms voc 5 unit
gurjotkawatra
 
Understanding Locking Mechanisms in Database Systems
Understanding Locking Mechanisms in Database SystemsUnderstanding Locking Mechanisms in Database Systems
Understanding Locking Mechanisms in Database Systems
kiansahafi
 
SQL locks-presentation
SQL locks-presentationSQL locks-presentation
SQL locks-presentation
Nuzhat Bhat
 
Locking unit 1 topic 3
Locking unit 1 topic 3Locking unit 1 topic 3
Locking unit 1 topic 3avniS
 
Pl sql-ch3
Pl sql-ch3Pl sql-ch3
Pl sql-ch3
Mukesh Tekwani
 
Database consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MXDatabase consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MX
Frans Jongma
 
Look inside the locking mechanism
Look inside the locking mechanismLook inside the locking mechanism
Look inside the locking mechanism
Liron Amitzi
 
Vani dbms
Vani dbmsVani dbms
Vani dbms
SangeethaSasi1
 
Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Oliersqlserver.co.il
 
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docxDBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
randyburney60861
 
Rdbms
RdbmsRdbms
Type LocK based in Concurrency Control.pptx
Type LocK based in Concurrency Control.pptxType LocK based in Concurrency Control.pptx
Type LocK based in Concurrency Control.pptx
emilinshyni2020
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
Jacob Zvirikuzhe
 
Concurrenty control
Concurrenty controlConcurrenty control
Concurrenty control
Faiza Hafeez
 
Database security
Database securityDatabase security
Database security
Javed Khan
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
Boris Hristov
 
NoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQL
NoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQLNoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQL
NoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQL
DATAVERSITY
 

Similar to Locking and concurrency (20)

Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
 
Locking And Concurrency
Locking And ConcurrencyLocking And Concurrency
Locking And Concurrency
 
Managing Memory & Locks - Series 2 Transactions & Lock management
Managing  Memory & Locks - Series 2 Transactions & Lock managementManaging  Memory & Locks - Series 2 Transactions & Lock management
Managing Memory & Locks - Series 2 Transactions & Lock management
 
Dbms voc 5 unit
Dbms voc 5 unitDbms voc 5 unit
Dbms voc 5 unit
 
Understanding Locking Mechanisms in Database Systems
Understanding Locking Mechanisms in Database SystemsUnderstanding Locking Mechanisms in Database Systems
Understanding Locking Mechanisms in Database Systems
 
SQL locks-presentation
SQL locks-presentationSQL locks-presentation
SQL locks-presentation
 
Locking unit 1 topic 3
Locking unit 1 topic 3Locking unit 1 topic 3
Locking unit 1 topic 3
 
Pl sql-ch3
Pl sql-ch3Pl sql-ch3
Pl sql-ch3
 
Database consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MXDatabase consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MX
 
Look inside the locking mechanism
Look inside the locking mechanismLook inside the locking mechanism
Look inside the locking mechanism
 
Vani dbms
Vani dbmsVani dbms
Vani dbms
 
Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Olier
 
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docxDBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
 
Rdbms
RdbmsRdbms
Rdbms
 
Type LocK based in Concurrency Control.pptx
Type LocK based in Concurrency Control.pptxType LocK based in Concurrency Control.pptx
Type LocK based in Concurrency Control.pptx
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Concurrenty control
Concurrenty controlConcurrenty control
Concurrenty control
 
Database security
Database securityDatabase security
Database security
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
 
NoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQL
NoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQLNoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQL
NoSQL Now! Webinar Series: Migrating Security Policies from SQL to NoSQL
 

Recently uploaded

Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 

Recently uploaded (20)

Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 

Locking and concurrency

  • 2. Multi-user concurrent and consistent access to the database structure is the biggest challenge. Locking and Concurrency ensures that every user can read and change the data consistently. Oracle is rather good at it.
  • 3. LOCKING A lock is a mechanism used to arrange concurrent access to a shared resource. Oracle locks table data at the row level, but it also uses locks at many other levels to provide concurrent access to various resources.
  • 4. LOCKING ISSUES Lock mechanism have to some issues. It is caused by bad design. +Lost Updates +Pessimistic Locking +Optimistic Locking +Blocking -Blockend Inserts -Blocked Updates and Deletes -Deadlocks -Lock Escalation
  • 6. Types of Lock DML Lock : DML locks guarantee the integrity of the data accessed by multiple users at the same time. - TX(Transaction) Locks : A TX lock is acquired when a transaction initiates its first change, and is held until the transaction performs a COMMIT or ROLLBACK. - TM Locks : These locks are used to ensure that the structure of a table is not altered while you are modifying its contents.
  • 7. DDL Locks : DDL locks are automatically placed against objects during a DDL operation to protect them from changes by other sessions. DDL locks are held for the duration of the DDL statement, and are released immediately afterwards. There are 3 kinds of DDL LOCK. - Exclusive DDL Locks - Share DDL Locks - Breakable Parse Locks
  • 8. Latches and Internal Locks : Latches and enqueues are lightweight serialization devices used to coordinate multi-user access to shared data structures, objects and files. Latches are locks that are held for extremely short periods of time, for example the t me it takes to modify an in memory data structure.
  • 9. Manual Locking The SELECT...FOR UPDATE statement is the predominant method of manually locking data. We can also manually lock data using the LOCK TABLE statement. You might use the LOCK TABLE IN EXCLUSIVE MODE statement if you were writing a large batch update that would affect most of the rows in a given table, and you wanted to be sure that no one would ʹblockʹ you.
  • 10. What is Concurrency Control ? Concurrency controls are the collection of functions that the database provides in order to allow many people to access and modify data simultaneously. The lock mechanism affects concurrency. Oracle's multi-versioning model for read consistency is always applied at the statement level and can also be applied at the transaction level.
  • 11. TRANSACTION ISOLATION LEVEL The SQL92 standard defines four levels of transaction isolation, with different possible outcomes for the same transaction scenario. These isolation levels are defined in terms of three phenomena that are either permitted or not at a given isolation level: - Dirty Read - Non-Repeatable Read - Phantom Read
  • 12. Isolation Levels Repeatable Read : Data that has been updated but has not yet been initialized cannot be read or updated by other transactions until it has been committed. Read Committed : Data that is being updated by other transactions cannot be read until the update process is complete. Read Uncommitted : Data that is being updated by other transactions but that has not yet been updated can be read.
  • 13. Serializable : This is generally considered the most restrictive level of transaction isolation, but provides the highest degree of isolation. Serializable transactions see only those changes that were committed at the time the transaction began, plus those changes made by the transaction itself through INSERT, UPDATE, and DELETE statements. Serializable transactions do not experience nonrepeatable reads or phantoms.