SlideShare a Scribd company logo
1 of 29
WELCOME  TO  THE  NIGHTMARE  OF  
LOCKING,  BLOCKING  
AND  ISOLATION  LEVELS!
Boris  Hristov
PASS  Virtual  Chapter  07/12/2013
So  Who  Am  I?
—  SQL  Server  DBA  at  HP
—  Trainer  and  Speaker
—  MCITP,  MCSE,  MCT
—  brshristov@live.com 

—  www.borishristov.com
       @BorisHristov
Agenda…
Locks.  What  is  there  for  us?
TroubleshooYng  locking  problems
TransacYon  IsolaYon  Levels
Locks.  What  is  there  for  us?
Methods  of  Concurrency  Control
Two  main  concurrency  control  types:
1.  PessimisYc
2.  OpYmisYc
      
  
                                                    –  SQL  Server  uses  locks,  causes  blocks  and  who  said  deadlocks?  
                                                  –  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:	
  	
  Preven&ng	
  incompa&ble	
  locks	
  
Dura0on:	
  End	
  of	
  the	
  transac&on	
  
Shared	
  (S)	
  
	
  
Used	
  for:	
  Reading	
  
Dura0on:	
  Released	
  almost	
  immediately	
  
(depends	
  on	
  the	
  isola&on	
  level)
Update	
  (U)	
  
	
  
Used	
  for:	
  Preparing	
  to	
  modify	
  
Dura0on:	
  End	
  of	
  the	
  transac&on	
  or	
  un&l	
  
converted	
  to	
  exclusive	
  (X)
Exclusive	
  (X)	
  
	
  
Used	
  for:	
  Modifying	
  
Dura0on:	
  End	
  of	
  the	
  transac&on
Lock  CompaYbility
	
   Not  all  locks  are  compaYble  with  other  locks.  

Lock
 Shared
 Update
 Exclusive
Shared  (S)
P	
   P	
   X	
  
Update  (U)

 P	
   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='Microsoi,  Bulgaria'  
WHERE  AddressID=2

S
IX
Header	
  
Row	
  
Row	
  
Row	
  
Row	
  
Row	
  
IX
X
A  query!  J
Methods  to  View  Locking  InformaYon
Dynamic  
Management  
Views
SQL  Server  Profiler  
or  Extended  
Events
Performance  
monitor  or  AcYvity  
Monitor
TroubleshooYng  locking  problems
Locking  and  blocking
Locking  and  blocking  are  oien  confused!
  
Locking
• The  acYon  of  taking  and  potenYally  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  mulYuser  environment,  there  is  always,  always  blocking!
• Only  a  problem  if  it  lasts  too  long
SQL  Server  decides  (during  compilaYon)  the  granularity  of  locks  to  be  used:
•  Row
•  Page
Lock  granularity  can  be  controlled  via  LOCK  HINTS  (PAGLOCK,  TABLOCKX,  etc…)
EscalaYon  always  happens  this  way:
Row  -­‐>  table  lock  (or  parYYon  lock  if  possible)
Page  -­‐>  table  lock  (or  parYYon  lock  if  possible)
Lock  escalaYon  can  be  disabled:
•  Trace  flag  1211  –  disables  lock  escalaYon  on  server  level
•  Trace  flag  1224  –  disables  lock  escalaYon  on  server  level  unYl  40%  of  the  memory  used  is  
consumed
Lock  granularity  and  escalaYon
Lock  escalaYon
S
S
X
>=  5000
IX
X
X
X
X
IX
Switch  the  escalaYon  level  (per  table)





AUTO  –  ParYYon-­‐level  escalaYon  if  the  table  is  parYYoned
TABLE  –  Always  table-­‐level  escalaYon
DISABLE  –  Do  not  escalate  unYl  absolutely  necessary    
Controlling  Lock  escalaYon
SELECT  lock_escalaYon_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  vicYm?
•  Cost  for  Rollback
•  Deadlock  priority  –  SET  DEADLOCK_PRIOIRTY
Resolve  blocking  a.k.a  live  locking
How  to  resolve  blocking  problems:
1.  Keep  the  transacYons  as  short  as  possible
2.  No  user  interacYons  required  in  the  middle  of  the  
transacYon
3.  Use  indexes
4.  Consider  a  server  to  offload  some  of  the  workloads
5.  Choose  isolaYon  level
DEMO    
Monitor  for  locks  with  xEvents
Lock  escalaYon  –  both  to  table  and  parYYon
Deadlock  and  the  SET  DEADLOCK_PRIORITY  opYon
TransacYon  isolaYon  levels
SET	
  TRANSACTION	
  ISOLATION	
  LEVEL	
  READ	
  UNCOMMITTED	
  (NOLOCK?)	
  	
  
Transaction 1
Transaction 2
	
   Sugges0on:	
  BePer	
  offload	
  the	
  reads	
  or	
  go	
  with	
  op&mis&c	
  level	
  concurrency!	
  
Select
Update
eXclusive lock
Read  Uncommixed  
(pessimisYc  concurrency  control)
Dirty read
SET	
  TRANSACTION	
  ISOLATION	
  LEVEL	
  REPEATABLE	
  READ	
  
Transaction 1 S(hared) lock
select
	
   No	
  non-­‐repeatable	
  reads	
  possible	
  (updates	
  during	
  Transac&on	
  1)	
  
	
   Phantom	
  records	
  s&ll	
  possible	
  (inserts	
  during	
  Transac&on	
  1)	
  	
  
Update
Transaction 2
Repeatable  Read  
(pessimisYc  concurrency  control)
Transaction 1 S(hared) lock
select
	
   Even	
  phantom	
  records	
  are	
  not	
  possible!	
  
	
   Highest	
  pessimis&c	
  level	
  of	
  isola&on,	
  lowest	
  level	
  of	
  concurrency	
  
	
  
Insert
Transaction 2
Serializable  
(pessimisYc  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	
  modifica&on	
  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	
  
OpYmisYc  Concurrency
  RCSI	
  –	
  Read	
  CommiHed	
  Snapshot	
  Isola0on	
  Level	
  
◦  Statement	
  level	
  versioning	
  	
  
◦  Requires	
  ALTER	
  DATABASE	
  SET	
  READ_COMMITTED_SNAPSHOT	
  ON	
  
	
   Snapshot	
  Isola0on	
  Level	
  
◦  Transac&on	
  level	
  versioning	
  
◦  Requires	
  ALTER	
  DATABASE	
  SET	
  ALLOW_SNAPSHOT_ISOLATION	
  ON	
  
◦  Requires	
  SET	
  TRANSACTION	
  ISOLATION	
  LEVEL	
  SNAPSHOT	
  
RCSI  and  SI  
(opYmisYc  concurrency  control)
DEMO    
Playing  around  with  the  IsolaYon  levels
Summary
	
   Blocking	
  is	
  something	
  normal	
  when	
  it’s	
  not	
  for	
  long	
  
	
   There	
  are	
  hundreds	
  of	
  thousands	
  of	
  ways	
  to	
  monitor	
  locking	
  and	
  blocking	
  
	
   Be	
  extremely	
  careful	
  for	
  lock	
  escala&ons	
  
	
   Choosing	
  the	
  Isola&on	
  level	
  is	
  also	
  a	
  business	
  decision!	
  
	
  
Resources
MCM  Readiness  videos  on  locking  lecture  and  demo
MCM  Readiness  video  on  Snapshot  IsolaYon  Level
hxp://blogs.msdn.com/b/bartd/archive/tags/sql+locking/
hxp://www.sqlskills.com/blogs/paul/category/locking/
Lock  hints  -­‐  
hxp://www.techrepublic.com/arYcle/control-­‐sql-­‐server-­‐
locking-­‐with-­‐hints/5181472
Thank  you.
…  and  don’t  forget  for  the  Google  Hangouts!
?

More Related Content

What's hot

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
 
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
 
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
 
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
 
Deep Into Isolation Levels
Deep Into Isolation LevelsDeep Into Isolation Levels
Deep Into 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
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyBoris Hristov
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction ManagementMark Ginnebaugh
 
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
 
Large Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQLLarge Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQLDaniël van Eeden
 
Protecting MySQL Network traffic
Protecting MySQL Network trafficProtecting MySQL Network traffic
Protecting MySQL Network trafficDaniël van Eeden
 
MariaDB MaxScale: an Intelligent Database Proxy
MariaDB MaxScale:  an Intelligent Database ProxyMariaDB MaxScale:  an Intelligent Database Proxy
MariaDB MaxScale: an Intelligent Database ProxyMarkus Mäkelä
 
Buytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerBuytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerkuchinskaya
 
Dynamo Amazon’s Highly Available Key-value Store
Dynamo Amazon’s Highly Available Key-value StoreDynamo Amazon’s Highly Available Key-value Store
Dynamo Amazon’s Highly Available Key-value StoreMiro Cupak
 
SSL, X.509, HTTPS - How to configure your HTTPS server
SSL, X.509, HTTPS - How to configure your HTTPS serverSSL, X.509, HTTPS - How to configure your HTTPS server
SSL, X.509, HTTPS - How to configure your HTTPS serverhannob
 
SQL Server Blocking Analysis
SQL Server Blocking AnalysisSQL Server Blocking Analysis
SQL Server Blocking AnalysisHậu Võ Tấn
 
MariaDB MaxScale: an Intelligent Database Proxy
MariaDB MaxScale: an Intelligent Database ProxyMariaDB MaxScale: an Intelligent Database Proxy
MariaDB MaxScale: an Intelligent Database ProxyMarkus Mäkelä
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleMariaDB plc
 

What's hot (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!
 
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!
 
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!
 
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!
 
Deep Into Isolation Levels
Deep Into Isolation LevelsDeep Into Isolation Levels
Deep Into 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!
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server Concurrency
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction Management
 
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)
 
Large Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQLLarge Scale Deployment of SSL/TLS For MySQL
Large Scale Deployment of SSL/TLS For MySQL
 
Protecting MySQL Network traffic
Protecting MySQL Network trafficProtecting MySQL Network traffic
Protecting MySQL Network traffic
 
MariaDB MaxScale: an Intelligent Database Proxy
MariaDB MaxScale:  an Intelligent Database ProxyMariaDB MaxScale:  an Intelligent Database Proxy
MariaDB MaxScale: an Intelligent Database Proxy
 
Buytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerBuytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemaker
 
Dynamo Amazon’s Highly Available Key-value Store
Dynamo Amazon’s Highly Available Key-value StoreDynamo Amazon’s Highly Available Key-value Store
Dynamo Amazon’s Highly Available Key-value Store
 
SSL, X.509, HTTPS - How to configure your HTTPS server
SSL, X.509, HTTPS - How to configure your HTTPS serverSSL, X.509, HTTPS - How to configure your HTTPS server
SSL, X.509, HTTPS - How to configure your HTTPS server
 
Locking And Concurrency
Locking And ConcurrencyLocking And Concurrency
Locking And Concurrency
 
SQL Server Blocking Analysis
SQL Server Blocking AnalysisSQL Server Blocking Analysis
SQL Server Blocking Analysis
 
MariaDB MaxScale: an Intelligent Database Proxy
MariaDB MaxScale: an Intelligent Database ProxyMariaDB MaxScale: an Intelligent Database Proxy
MariaDB MaxScale: an Intelligent Database Proxy
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScale
 

Viewers also liked

Corporate Social Responsibility
Corporate Social Responsibility Corporate Social Responsibility
Corporate Social Responsibility Prateek Singh
 
Histórico mundial
Histórico mundialHistórico mundial
Histórico mundialUNIPLETRAS
 
Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016
Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016
Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016Jason Currie
 
SIGN LANGUAGE IN NIGERIA
SIGN LANGUAGE IN NIGERIASIGN LANGUAGE IN NIGERIA
SIGN LANGUAGE IN NIGERIAItohowo Okon
 
El plástico
El plásticoEl plástico
El plásticoNataliaVp
 
AppFolio Reporting Features (Customer Webinar Slides)
AppFolio Reporting Features (Customer Webinar Slides)AppFolio Reporting Features (Customer Webinar Slides)
AppFolio Reporting Features (Customer Webinar Slides)AppFolio
 
4 ways to segment users and achieve your marketing goals vizury
4 ways to segment users and achieve your marketing goals vizury4 ways to segment users and achieve your marketing goals vizury
4 ways to segment users and achieve your marketing goals vizuryVizury - Growth Marketing Platform
 
Jonas Esteves Arte e Tecnologia - artistas e aplicacao - artistas e aplicacao
Jonas Esteves  Arte e Tecnologia - artistas e aplicacao - artistas e aplicacaoJonas Esteves  Arte e Tecnologia - artistas e aplicacao - artistas e aplicacao
Jonas Esteves Arte e Tecnologia - artistas e aplicacao - artistas e aplicacaoJonas Esteves
 
Update on Supply Conditions and Drought Response Activities - July 23, 2015
Update on Supply Conditions and Drought Response Activities - July 23, 2015 Update on Supply Conditions and Drought Response Activities - July 23, 2015
Update on Supply Conditions and Drought Response Activities - July 23, 2015 San Diego County Water Authority
 
Pg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replicaPg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replicaFederico Campoli
 

Viewers also liked (13)

Corporate Social Responsibility
Corporate Social Responsibility Corporate Social Responsibility
Corporate Social Responsibility
 
Bab 2
Bab 2Bab 2
Bab 2
 
ASFA 2007 Web
ASFA 2007 WebASFA 2007 Web
ASFA 2007 Web
 
Histórico mundial
Histórico mundialHistórico mundial
Histórico mundial
 
Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016
Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016
Vanguard Health at Capricorn Coast: Rural Medicine Australia 2016
 
SIGN LANGUAGE IN NIGERIA
SIGN LANGUAGE IN NIGERIASIGN LANGUAGE IN NIGERIA
SIGN LANGUAGE IN NIGERIA
 
El plástico
El plásticoEl plástico
El plástico
 
511NA630.pdf
511NA630.pdf511NA630.pdf
511NA630.pdf
 
AppFolio Reporting Features (Customer Webinar Slides)
AppFolio Reporting Features (Customer Webinar Slides)AppFolio Reporting Features (Customer Webinar Slides)
AppFolio Reporting Features (Customer Webinar Slides)
 
4 ways to segment users and achieve your marketing goals vizury
4 ways to segment users and achieve your marketing goals vizury4 ways to segment users and achieve your marketing goals vizury
4 ways to segment users and achieve your marketing goals vizury
 
Jonas Esteves Arte e Tecnologia - artistas e aplicacao - artistas e aplicacao
Jonas Esteves  Arte e Tecnologia - artistas e aplicacao - artistas e aplicacaoJonas Esteves  Arte e Tecnologia - artistas e aplicacao - artistas e aplicacao
Jonas Esteves Arte e Tecnologia - artistas e aplicacao - artistas e aplicacao
 
Update on Supply Conditions and Drought Response Activities - July 23, 2015
Update on Supply Conditions and Drought Response Activities - July 23, 2015 Update on Supply Conditions and Drought Response Activities - July 23, 2015
Update on Supply Conditions and Drought Response Activities - July 23, 2015
 
Pg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replicaPg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replica
 

Similar to The nightmare of locking, blocking and isolation levels

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
 
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
 
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
 
Choosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or PessimisticChoosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or PessimisticVinod Kumar
 
Clustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And AvailabilityClustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And AvailabilityConSanFrancisco123
 
Database security
Database securityDatabase security
Database securityJaved Khan
 
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
 
Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000elliando dias
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMark Swarbrick
 
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
 
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
 
Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsJ On The Beach
 
Linux synchronization tools
Linux synchronization toolsLinux synchronization tools
Linux synchronization toolsmukul bhardwaj
 
Linux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emptionLinux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emptionHemanth Venkatesh
 
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
 

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

Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Olier
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
 
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
 
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
 
Choosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or PessimisticChoosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or Pessimistic
 
Clustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And AvailabilityClustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And Availability
 
Database security
Database securityDatabase security
Database security
 
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
 
Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
 
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
 
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...
 
Coding style for good synthesis
Coding style for good synthesisCoding style for good synthesis
Coding style for good synthesis
 
Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control Patterns
 
Linux synchronization tools
Linux synchronization toolsLinux synchronization tools
Linux synchronization tools
 
01 oracle architecture
01 oracle architecture01 oracle architecture
01 oracle architecture
 
Kernel
KernelKernel
Kernel
 
Gatling
GatlingGatling
Gatling
 
Linux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emptionLinux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emption
 
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...
 

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 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 (17)

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 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

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

The nightmare of locking, blocking and isolation levels

  • 1. WELCOME  TO  THE  NIGHTMARE  OF   LOCKING,  BLOCKING   AND  ISOLATION  LEVELS! Boris  Hristov PASS  Virtual  Chapter  07/12/2013
  • 2. So  Who  Am  I? —  SQL  Server  DBA  at  HP —  Trainer  and  Speaker —  MCITP,  MCSE,  MCT —  brshristov@live.com —  www.borishristov.com      @BorisHristov
  • 3. Agenda… Locks.  What  is  there  for  us? TroubleshooYng  locking  problems TransacYon  IsolaYon  Levels
  • 4. Locks.  What  is  there  for  us?
  • 5. Methods  of  Concurrency  Control Two  main  concurrency  control  types: 1.  PessimisYc 2.  OpYmisYc                                                            –  SQL  Server  uses  locks,  causes  blocks  and  who  said  deadlocks?                                                    –  SQL  Server  generates  versions  for  everyone,  but  the  updates…
  • 6. 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    
  • 7. Common  lock  types Intent     Used  for:    Preven&ng  incompa&ble  locks   Dura0on:  End  of  the  transac&on   Shared  (S)     Used  for:  Reading   Dura0on:  Released  almost  immediately   (depends  on  the  isola&on  level) Update  (U)     Used  for:  Preparing  to  modify   Dura0on:  End  of  the  transac&on  or  un&l   converted  to  exclusive  (X) Exclusive  (X)     Used  for:  Modifying   Dura0on:  End  of  the  transac&on
  • 8. Lock  CompaYbility   Not  all  locks  are  compaYble  with  other  locks.   Lock Shared Update Exclusive Shared  (S) P   P   X   Update  (U) P   X   X   Exclusive  (X) X   X   X  
  • 10. Let’s  update  a  row.  What  do  we  need? USE  AdventureWorks2012 GO UPDATE  [Person].[Address] SET  AddressLine1='Microsoi,  Bulgaria'   WHERE  AddressID=2 S IX Header   Row   Row   Row   Row   Row   IX X A  query!  J
  • 11. Methods  to  View  Locking  InformaYon Dynamic   Management   Views SQL  Server  Profiler   or  Extended   Events Performance   monitor  or  AcYvity   Monitor
  • 13. Locking  and  blocking Locking  and  blocking  are  oien  confused!   Locking • The  acYon  of  taking  and  potenYally  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  mulYuser  environment,  there  is  always,  always  blocking! • Only  a  problem  if  it  lasts  too  long
  • 14. SQL  Server  decides  (during  compilaYon)  the  granularity  of  locks  to  be  used: •  Row •  Page Lock  granularity  can  be  controlled  via  LOCK  HINTS  (PAGLOCK,  TABLOCKX,  etc…) EscalaYon  always  happens  this  way: Row  -­‐>  table  lock  (or  parYYon  lock  if  possible) Page  -­‐>  table  lock  (or  parYYon  lock  if  possible) Lock  escalaYon  can  be  disabled: •  Trace  flag  1211  –  disables  lock  escalaYon  on  server  level •  Trace  flag  1224  –  disables  lock  escalaYon  on  server  level  unYl  40%  of  the  memory  used  is   consumed Lock  granularity  and  escalaYon
  • 16. Switch  the  escalaYon  level  (per  table) AUTO  –  ParYYon-­‐level  escalaYon  if  the  table  is  parYYoned TABLE  –  Always  table-­‐level  escalaYon DISABLE  –  Do  not  escalate  unYl  absolutely  necessary     Controlling  Lock  escalaYon SELECT  lock_escalaYon_desc FROM  sys.tables WHERE  name  =  'Person.Address' ALTER  TABLE  Person.Address  SET  (LOCK_ESCALATION  =  {AUTO  |  TABLE  |  DISABLE}
  • 17. What  Are  Deadlocks? Task  A Task  B Resource  1 Resource  2 Who  is  vicYm? •  Cost  for  Rollback •  Deadlock  priority  –  SET  DEADLOCK_PRIOIRTY
  • 18. Resolve  blocking  a.k.a  live  locking How  to  resolve  blocking  problems: 1.  Keep  the  transacYons  as  short  as  possible 2.  No  user  interacYons  required  in  the  middle  of  the   transacYon 3.  Use  indexes 4.  Consider  a  server  to  offload  some  of  the  workloads 5.  Choose  isolaYon  level
  • 19. DEMO     Monitor  for  locks  with  xEvents Lock  escalaYon  –  both  to  table  and  parYYon Deadlock  and  the  SET  DEADLOCK_PRIORITY  opYon
  • 21. SET  TRANSACTION  ISOLATION  LEVEL  READ  UNCOMMITTED  (NOLOCK?)     Transaction 1 Transaction 2   Sugges0on:  BePer  offload  the  reads  or  go  with  op&mis&c  level  concurrency!   Select Update eXclusive lock Read  Uncommixed   (pessimisYc  concurrency  control) Dirty read
  • 22. SET  TRANSACTION  ISOLATION  LEVEL  REPEATABLE  READ   Transaction 1 S(hared) lock select   No  non-­‐repeatable  reads  possible  (updates  during  Transac&on  1)     Phantom  records  s&ll  possible  (inserts  during  Transac&on  1)     Update Transaction 2 Repeatable  Read   (pessimisYc  concurrency  control)
  • 23. Transaction 1 S(hared) lock select   Even  phantom  records  are  not  possible!     Highest  pessimis&c  level  of  isola&on,  lowest  level  of  concurrency     Insert Transaction 2 Serializable   (pessimisYc  concurrency  control) SET  TRANSACTION  ISOLATION  LEVEL  SERIALIZABLE  
  • 24.   Based  on  Row  versioning  (stored  inside  tempdb’s  version  store  area)     ◦  No  dirty,  non-­‐repeatable  reads  or  phantom  records   ◦  Every  single  modifica&on  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   OpYmisYc  Concurrency
  • 25.   RCSI  –  Read  CommiHed  Snapshot  Isola0on  Level   ◦  Statement  level  versioning     ◦  Requires  ALTER  DATABASE  SET  READ_COMMITTED_SNAPSHOT  ON     Snapshot  Isola0on  Level   ◦  Transac&on  level  versioning   ◦  Requires  ALTER  DATABASE  SET  ALLOW_SNAPSHOT_ISOLATION  ON   ◦  Requires  SET  TRANSACTION  ISOLATION  LEVEL  SNAPSHOT   RCSI  and  SI   (opYmisYc  concurrency  control)
  • 26. DEMO     Playing  around  with  the  IsolaYon  levels
  • 27. Summary   Blocking  is  something  normal  when  it’s  not  for  long     There  are  hundreds  of  thousands  of  ways  to  monitor  locking  and  blocking     Be  extremely  careful  for  lock  escala&ons     Choosing  the  Isola&on  level  is  also  a  business  decision!    
  • 28. Resources MCM  Readiness  videos  on  locking  lecture  and  demo MCM  Readiness  video  on  Snapshot  IsolaYon  Level hxp://blogs.msdn.com/b/bartd/archive/tags/sql+locking/ hxp://www.sqlskills.com/blogs/paul/category/locking/ Lock  hints  -­‐   hxp://www.techrepublic.com/arYcle/control-­‐sql-­‐server-­‐ locking-­‐with-­‐hints/5181472
  • 29. Thank  you. …  and  don’t  forget  for  the  Google  Hangouts! ?