SlideShare a Scribd company logo
1 of 31
The Nightmare of Locking,
Blocking and Isolation Levels
So who am I?
@BorisHristov
So who am I?
Agenda…
Locks. What is there for us?
Troubleshooting locking problems
Transaction Isolation Levels
Locks. What is there for us?
Methods of Concurrency Control
1. Pessimistic
– SQL Server uses locks, causes blocks and who said deadlocks?
2. Optimistic
– SQL Server generates versions for everyone, but the updates…
What Are Locks and what is locking?
Lock – internal memory structure that “tells” us what we all do with the
resources inside the system
Locking – mechanism to protect the resources and guarantee consistent data
Common lock types
Intent
Used for: Preventing incompatible
locks
Duration: End of the transaction
Shared (S)
Used for: Reading
Duration: Released almost
immediately
(depends on the isolation level)
Update (U)
Used for: Preparing to modify
Duration: End of the transaction or
until converted to exclusive (X)
Exclusive (X)
Used for: Modifying
Duration: End of the transaction
Lock Compatibility
Not all locks are compatible with other locks.
Lock Shared Update Exclusive
Shared (S)
  X
Update (U)
 X X
Exclusive (X)
X X X
Lock Hierarchy
Database
Table
Page
Row
Let’s update a row!
What do we need?
USE AdventureWorks2012
GO
UPDATE [Person].[Address]
SET AddressLine1=’Zagreb,Croatia'
WHERE AddressID=2
S
IX
Header
Row
Row
Row
Row
Row
IX
X
How to View Locking Information
Dynamic
Management
Views
SQL Server
Profiler or
Extended
Events
Performance
monitor or Activity
Monitor
Troubleshooting
Locking Problems
Locking and blocking
Locking and blocking are often confused!
Locking
• The action of taking and potentially holding locks
• Used to implement concurrency control
Blocking is result of locking!
• One process needs to wait for another process to release locked
resources
• In a multiuser environment, there is always, always blocking!
• Only a problem if it lasts too long
Lock escalationS
S
X
>= 5000
IX
Header
Row
Row
Row
Row
Row
X
X
X
IX
X
1. Switch the escalation level (per table)
AUTO – Partition-level escalation if the table is partitioned
TABLE – Always table-level escalation
DISABLE – Do not escalate until absolutely necessary
2. Just disable it (that’s not Nike’s “Just do it!”)
• Trace flag 1211 – disables lock escalation on server level
• Trace flag 1224 – disables lock escalation if 40% of the memory used is consumed
Controlling Lock escalation
SELECT lock_escalation_desc
FROM sys.tables
WHERE name = 'Person.Address'
ALTER TABLE Person.Address SET (LOCK_ESCALATION = {AUTO |
TABLE | DISABLE}
What Are Deadlocks?
Task A
Task B
Resource 1
Resource 2
Who is victim?
• Cost for Rollback
• Deadlock priority – SET DEADLOCK_PRIOIRTY
Resolve blocking a.k.a live locking
1. Keep the transactions as short as possible
2. No user interactions required in the middle of the transaction
3. Use indexes (proper ones)
4. Consider a server to offload some of the workloads
5. Choose isolation level
DEMO
Monitor for locks with xEvents
Lock escalation – both to table and partition
Deadlock and the SET DEADLOCK_PRIORITY option
Transaction
Isolation Levels
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
(NOLOCK?)
Transaction 1
Transaction 2
Suggestion: Better offload the reads or go with optimistic level concurrency!
Select
Update
eXclusive lock
Read Uncommitted
(pessimistic concurrency control)
Dirty read
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
Transaction 1 S(hared) lock
select
No non-repeatable reads possible (updates during Transaction 1)
Phantom records still possible (inserts during Transaction 1)
Update
Transaction 2
Repeatable Read
(pessimistic concurrency control)
Transaction 1 S(hared) lock
select
Even phantom records are not possible!
Highest pessimistic level of isolation, lowest level of concurrency
Insert
Transaction 2
Serializable
(pessimistic concurrency control)
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
Based on Row versioning (stored inside tempdb’s version store area)
• No dirty, non-repeatable reads or phantom records
• Every single modification is versioned even if not used
• Adds 14 bytes per row
Readers do not block writers and writers do not block readers
Writers can and will block writers, this can cause conflicts
Optimistic Concurrency
RCSI – Read Committed Snapshot Isolation Level
• Statement level versioning
• Requires ALTER DATABASE SET READ_COMMITTED_SNAPSHOT ON
Snapshot Isolation Level
• Transaction level versioning
• Requires ALTER DATABASE SET ALLOW_SNAPSHOT_ISOLATION ON
• Requires SET TRANSACTION ISOLATION LEVEL SNAPSHOT
RCSI and SI
(optimistic concurrency control)
V1 V2
Transaction 1
Transaction 2
Select in RCSISelect
Select in SI
DEMO
Playing around with the Isolation levels
Summary
1. Blocking is something normal when it’s not for long
2. There are numerous ways to monitor locking and blocking
3. Be extremely careful for lock escalations
4. Choosing the Isolation level is also a business decision!
Resources
MCM Readiness videos on locking lecture and demo
MCM Readiness video on Snapshot Isolation Level
http://blogs.msdn.com/b/bartd/archive/tags/sql+locking
http://www.sqlskills.com/blogs/paul/category/locking/
Lock hints -
http://www.techrepublic.com/article/control-sql-server-
locking-with-hints/5181472
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!

More Related Content

What's hot

Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Boris Hristov
 
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
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsBoris Hristov
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Boris Hristov
 
LMAX Disruptor - High Performance Inter-Thread Messaging Library
LMAX Disruptor - High Performance Inter-Thread Messaging LibraryLMAX Disruptor - High Performance Inter-Thread Messaging Library
LMAX Disruptor - High Performance Inter-Thread Messaging LibrarySebastian Andrasoni
 
The Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation LevelsThe Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation LevelsBoris Hristov
 
Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Neena R Krishna
 
An End to Order (many cores with java, session two)
An End to Order (many cores with java, session two)An End to Order (many cores with java, session two)
An End to Order (many cores with java, session two)Robert Burrell Donkin
 
Reader/writer problem
Reader/writer problemReader/writer problem
Reader/writer problemRinkuMonani
 
Disruptor 2015-12-22 @ java.il
Disruptor 2015-12-22 @ java.ilDisruptor 2015-12-22 @ java.il
Disruptor 2015-12-22 @ java.ilAmir Langer
 
Encryption oracle
Encryption oracleEncryption oracle
Encryption oraclemanong007
 
Distributed Systems Theory for Mere Mortals - GeeCON Krakow May 2017
Distributed Systems Theory for Mere Mortals -  GeeCON Krakow May 2017Distributed Systems Theory for Mere Mortals -  GeeCON Krakow May 2017
Distributed Systems Theory for Mere Mortals - GeeCON Krakow May 2017Ensar Basri Kahveci
 
Thread presentation
Thread presentationThread presentation
Thread presentationAAshish Ojha
 
Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017
Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017 Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017
Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017 Ensar Basri Kahveci
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Boris Hristov
 

What's hot (20)

Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
 
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!
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
 
LMAX Disruptor - High Performance Inter-Thread Messaging Library
LMAX Disruptor - High Performance Inter-Thread Messaging LibraryLMAX Disruptor - High Performance Inter-Thread Messaging Library
LMAX Disruptor - High Performance Inter-Thread Messaging Library
 
The Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation LevelsThe Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation Levels
 
An End to Order
An End to OrderAn End to Order
An End to Order
 
Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...
 
An End to Order (many cores with java, session two)
An End to Order (many cores with java, session two)An End to Order (many cores with java, session two)
An End to Order (many cores with java, session two)
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Reader/writer problem
Reader/writer problemReader/writer problem
Reader/writer problem
 
Disruptor 2015-12-22 @ java.il
Disruptor 2015-12-22 @ java.ilDisruptor 2015-12-22 @ java.il
Disruptor 2015-12-22 @ java.il
 
Encryption oracle
Encryption oracleEncryption oracle
Encryption oracle
 
Distributed Systems Theory for Mere Mortals - GeeCON Krakow May 2017
Distributed Systems Theory for Mere Mortals -  GeeCON Krakow May 2017Distributed Systems Theory for Mere Mortals -  GeeCON Krakow May 2017
Distributed Systems Theory for Mere Mortals - GeeCON Krakow May 2017
 
Thread presentation
Thread presentationThread presentation
Thread presentation
 
Lstm
LstmLstm
Lstm
 
Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017
Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017 Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017
Distributed Systems Theory for Mere Mortals - Java Day Istanbul May 2017
 
VXCON 2017
VXCON 2017VXCON 2017
VXCON 2017
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
 

Viewers also liked

MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017Ivan Ma
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLOlivier DASINI
 
MySQL High Availability with Group Replication
MySQL High Availability with Group ReplicationMySQL High Availability with Group Replication
MySQL High Availability with Group ReplicationNuno Carvalho
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourRonald Bradford
 
MySQL InnoDB Cluster and Group Replication - OSI 2017 Bangalore
MySQL InnoDB Cluster and Group Replication - OSI 2017 BangaloreMySQL InnoDB Cluster and Group Replication - OSI 2017 Bangalore
MySQL InnoDB Cluster and Group Replication - OSI 2017 BangaloreSujatha Sivakumar
 
Mastering InnoDB Diagnostics
Mastering InnoDB DiagnosticsMastering InnoDB Diagnostics
Mastering InnoDB Diagnosticsguest8212a5
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationKenny Gryp
 
Group Replication: A Journey to the Group Communication Core
Group Replication: A Journey to the Group Communication CoreGroup Replication: A Journey to the Group Communication Core
Group Replication: A Journey to the Group Communication CoreAlfranio Júnior
 
MySQL InnoDB 源码实现分析(一)
MySQL InnoDB 源码实现分析(一)MySQL InnoDB 源码实现分析(一)
MySQL InnoDB 源码实现分析(一)frogd
 
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyMySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyContinuent
 
MySQL High Availability Solutions
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability SolutionsLenz Grimmer
 
Capturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLCapturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLRonald Bradford
 
What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...Sveta Smirnova
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationManish Kumar
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability Mydbops
 
MySQL High-Availability and Scale-Out architectures
MySQL High-Availability and Scale-Out architecturesMySQL High-Availability and Scale-Out architectures
MySQL High-Availability and Scale-Out architecturesFromDual GmbH
 

Viewers also liked (20)

SQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and ProfitSQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and Profit
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
 
MySQL High Availability with Group Replication
MySQL High Availability with Group ReplicationMySQL High Availability with Group Replication
MySQL High Availability with Group Replication
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
 
MySQL InnoDB Cluster and Group Replication - OSI 2017 Bangalore
MySQL InnoDB Cluster and Group Replication - OSI 2017 BangaloreMySQL InnoDB Cluster and Group Replication - OSI 2017 Bangalore
MySQL InnoDB Cluster and Group Replication - OSI 2017 Bangalore
 
Mastering InnoDB Diagnostics
Mastering InnoDB DiagnosticsMastering InnoDB Diagnostics
Mastering InnoDB Diagnostics
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
Group Replication: A Journey to the Group Communication Core
Group Replication: A Journey to the Group Communication CoreGroup Replication: A Journey to the Group Communication Core
Group Replication: A Journey to the Group Communication Core
 
MySQL InnoDB 源码实现分析(一)
MySQL InnoDB 源码实现分析(一)MySQL InnoDB 源码实现分析(一)
MySQL InnoDB 源码实现分析(一)
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyMySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
 
MySQL High Availability Solutions
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability Solutions
 
Capturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLCapturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQL
 
What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability
 
MySQL High-Availability and Scale-Out architectures
MySQL High-Availability and Scale-Out architecturesMySQL High-Availability and Scale-Out architectures
MySQL High-Availability and Scale-Out architectures
 
Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 

Similar to 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!
The Nightmare of Locking, Blocking and Isolation Levels!Boris Hristov
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...Bob Pusateri
 
Deep Into Isolation Levels
Deep Into Isolation LevelsDeep Into Isolation Levels
Deep Into Isolation LevelsBoris Hristov
 
MySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveMySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveUlf Wendel
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...Bob Pusateri
 
DIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL ClusterDIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL ClusterUlf Wendel
 
Best Practice for Achieving High Availability in MariaDB
Best Practice for Achieving High Availability in MariaDBBest Practice for Achieving High Availability in MariaDB
Best Practice for Achieving High Availability in MariaDBMariaDB plc
 
MariaDB High Availability Webinar
MariaDB High Availability WebinarMariaDB High Availability Webinar
MariaDB High Availability WebinarMariaDB plc
 
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
 
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 managementDAGEOP LTD
 
1.8 Data Protection.pdf
1.8 Data Protection.pdf1.8 Data Protection.pdf
1.8 Data Protection.pdfssuser8b6c85
 
Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Antonios Chatzipavlis
 
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and LockingGeek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and LockingIDERA Software
 
02 2017 emea_roadshow_milan_ha
02 2017 emea_roadshow_milan_ha02 2017 emea_roadshow_milan_ha
02 2017 emea_roadshow_milan_hamlraviol
 
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...MongoDB
 

Similar to The nightmare of locking, blocking and isolation levels! (20)

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!
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
 
Deep Into Isolation Levels
Deep Into Isolation LevelsDeep Into Isolation Levels
Deep Into Isolation Levels
 
MySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveMySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspective
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
 
DIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL ClusterDIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL Cluster
 
Best Practice for Achieving High Availability in MariaDB
Best Practice for Achieving High Availability in MariaDBBest Practice for Achieving High Availability in MariaDB
Best Practice for Achieving High Availability in MariaDB
 
MariaDB High Availability Webinar
MariaDB High Availability WebinarMariaDB High Availability Webinar
MariaDB High Availability Webinar
 
Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Olier
 
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
 
1.8 Data Protection.pdf
1.8 Data Protection.pdf1.8 Data Protection.pdf
1.8 Data Protection.pdf
 
Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)
 
Kernel
KernelKernel
Kernel
 
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and LockingGeek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
 
02 2017 emea_roadshow_milan_ha
02 2017 emea_roadshow_milan_ha02 2017 emea_roadshow_milan_ha
02 2017 emea_roadshow_milan_ha
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
 
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
 

More from Boris Hristov

The Secret to Engaging Presentations
The Secret to Engaging PresentationsThe Secret to Engaging Presentations
The Secret to Engaging PresentationsBoris Hristov
 
Presentation Design Fundamentals
Presentation Design FundamentalsPresentation Design Fundamentals
Presentation Design FundamentalsBoris Hristov
 
The World of Business Intelligence
The World of Business IntelligenceThe World of Business Intelligence
The World of Business IntelligenceBoris Hristov
 
The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014Boris Hristov
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Boris Hristov
 
How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!Boris Hristov
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Boris Hristov
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Boris Hristov
 
Presentation Skills: The Next Level
Presentation Skills: The Next LevelPresentation Skills: The Next Level
Presentation Skills: The Next LevelBoris Hristov
 
SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!Boris Hristov
 
BI PoC for the Telco Industry
BI PoC for the Telco IndustryBI PoC for the Telco Industry
BI PoC for the Telco IndustryBoris Hristov
 
Presentation Design Basics
Presentation Design BasicsPresentation Design Basics
Presentation Design BasicsBoris Hristov
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Boris Hristov
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyBoris Hristov
 
Database Performance
Database PerformanceDatabase Performance
Database PerformanceBoris Hristov
 
You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!Boris Hristov
 
First Steps with Microsoft SQL Server
First Steps with Microsoft SQL ServerFirst Steps with Microsoft SQL Server
First Steps with Microsoft SQL ServerBoris Hristov
 
Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014Boris Hristov
 

More from Boris Hristov (18)

The Secret to Engaging Presentations
The Secret to Engaging PresentationsThe Secret to Engaging Presentations
The Secret to Engaging Presentations
 
Presentation Design Fundamentals
Presentation Design FundamentalsPresentation Design Fundamentals
Presentation Design Fundamentals
 
The World of Business Intelligence
The World of Business IntelligenceThe World of Business Intelligence
The World of Business Intelligence
 
The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?
 
How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014
 
Presentation Skills: The Next Level
Presentation Skills: The Next LevelPresentation Skills: The Next Level
Presentation Skills: The Next Level
 
SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!
 
BI PoC for the Telco Industry
BI PoC for the Telco IndustryBI PoC for the Telco Industry
BI PoC for the Telco Industry
 
Presentation Design Basics
Presentation Design BasicsPresentation Design Basics
Presentation Design Basics
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server Concurrency
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!
 
First Steps with Microsoft SQL Server
First Steps with Microsoft SQL ServerFirst Steps with Microsoft SQL Server
First Steps with Microsoft SQL Server
 
Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014
 

Recently uploaded

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 

Recently uploaded (20)

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

The nightmare of locking, blocking and isolation levels!

  • 1.
  • 2. The Nightmare of Locking, Blocking and Isolation Levels
  • 3.
  • 4. So who am I? @BorisHristov So who am I?
  • 5. Agenda… Locks. What is there for us? Troubleshooting locking problems Transaction Isolation Levels
  • 6. Locks. What is there for us?
  • 7. Methods of Concurrency Control 1. Pessimistic – SQL Server uses locks, causes blocks and who said deadlocks? 2. Optimistic – SQL Server generates versions for everyone, but the updates…
  • 8. What Are Locks and what is locking? Lock – internal memory structure that “tells” us what we all do with the resources inside the system Locking – mechanism to protect the resources and guarantee consistent data
  • 9. Common lock types Intent Used for: Preventing incompatible locks Duration: End of the transaction Shared (S) Used for: Reading Duration: Released almost immediately (depends on the isolation level) Update (U) Used for: Preparing to modify Duration: End of the transaction or until converted to exclusive (X) Exclusive (X) Used for: Modifying Duration: End of the transaction
  • 10. Lock Compatibility Not all locks are compatible with other locks. Lock Shared Update Exclusive Shared (S)   X Update (U)  X X Exclusive (X) X X X
  • 12. Let’s update a row! What do we need? USE AdventureWorks2012 GO UPDATE [Person].[Address] SET AddressLine1=’Zagreb,Croatia' WHERE AddressID=2 S IX Header Row Row Row Row Row IX X
  • 13. How to View Locking Information Dynamic Management Views SQL Server Profiler or Extended Events Performance monitor or Activity Monitor
  • 15. Locking and blocking Locking and blocking are often confused! Locking • The action of taking and potentially holding locks • Used to implement concurrency control Blocking is result of locking! • One process needs to wait for another process to release locked resources • In a multiuser environment, there is always, always blocking! • Only a problem if it lasts too long
  • 17. 1. Switch the escalation level (per table) AUTO – Partition-level escalation if the table is partitioned TABLE – Always table-level escalation DISABLE – Do not escalate until absolutely necessary 2. Just disable it (that’s not Nike’s “Just do it!”) • Trace flag 1211 – disables lock escalation on server level • Trace flag 1224 – disables lock escalation if 40% of the memory used is consumed Controlling Lock escalation SELECT lock_escalation_desc FROM sys.tables WHERE name = 'Person.Address' ALTER TABLE Person.Address SET (LOCK_ESCALATION = {AUTO | TABLE | DISABLE}
  • 18. What Are Deadlocks? Task A Task B Resource 1 Resource 2 Who is victim? • Cost for Rollback • Deadlock priority – SET DEADLOCK_PRIOIRTY
  • 19. Resolve blocking a.k.a live locking 1. Keep the transactions as short as possible 2. No user interactions required in the middle of the transaction 3. Use indexes (proper ones) 4. Consider a server to offload some of the workloads 5. Choose isolation level
  • 20. DEMO Monitor for locks with xEvents Lock escalation – both to table and partition Deadlock and the SET DEADLOCK_PRIORITY option
  • 22. SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED (NOLOCK?) Transaction 1 Transaction 2 Suggestion: Better offload the reads or go with optimistic level concurrency! Select Update eXclusive lock Read Uncommitted (pessimistic concurrency control) Dirty read
  • 23. SET TRANSACTION ISOLATION LEVEL REPEATABLE READ Transaction 1 S(hared) lock select No non-repeatable reads possible (updates during Transaction 1) Phantom records still possible (inserts during Transaction 1) Update Transaction 2 Repeatable Read (pessimistic concurrency control)
  • 24. Transaction 1 S(hared) lock select Even phantom records are not possible! Highest pessimistic level of isolation, lowest level of concurrency Insert Transaction 2 Serializable (pessimistic concurrency control) SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
  • 25. Based on Row versioning (stored inside tempdb’s version store area) • No dirty, non-repeatable reads or phantom records • Every single modification is versioned even if not used • Adds 14 bytes per row Readers do not block writers and writers do not block readers Writers can and will block writers, this can cause conflicts Optimistic Concurrency
  • 26. RCSI – Read Committed Snapshot Isolation Level • Statement level versioning • Requires ALTER DATABASE SET READ_COMMITTED_SNAPSHOT ON Snapshot Isolation Level • Transaction level versioning • Requires ALTER DATABASE SET ALLOW_SNAPSHOT_ISOLATION ON • Requires SET TRANSACTION ISOLATION LEVEL SNAPSHOT RCSI and SI (optimistic concurrency control) V1 V2 Transaction 1 Transaction 2 Select in RCSISelect Select in SI
  • 27. DEMO Playing around with the Isolation levels
  • 28. Summary 1. Blocking is something normal when it’s not for long 2. There are numerous ways to monitor locking and blocking 3. Be extremely careful for lock escalations 4. Choosing the Isolation level is also a business decision!
  • 29. Resources MCM Readiness videos on locking lecture and demo MCM Readiness video on Snapshot Isolation Level http://blogs.msdn.com/b/bartd/archive/tags/sql+locking http://www.sqlskills.com/blogs/paul/category/locking/ Lock hints - http://www.techrepublic.com/article/control-sql-server- locking-with-hints/5181472