SQLintersection Locks, Blocks, and Deadlocks Oh My! Randy Knight Wednesday, 2:15-3:15.

Slides:



Advertisements
Similar presentations
Module 20 Troubleshooting Common SQL Server 2008 R2 Administrative Issues.
Advertisements

1096 Understanding InterBase Transactions Bill Todd The Database Group, Inc.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Module 15: Managing Transactions and Locks. Overview Introduction to Transactions and Locks Managing Transactions SQL Server Locking Managing Locks.
ACS-4902 R. McFadyen 1 Database Concurrency Control Deadlock Deadlock occurs when each transaction in a set is waiting for another transaction in the set.
9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency.
Transaction Management and Concurrency Control
Anil Desai Austin CodeCamp  Anil Desai ◦ Independent consultant (Austin, TX) ◦ Author of several SQL Server books ◦ Instructor, “Implementing and.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
Module 8: Server Management. Overview Server-level and instance-level resources such as memory and processes Database-level resources such as logical.
Managing Transaction and Lock Vu Tuyet Trinh Hanoi University of Technology 1.
1099 Why Use InterBase? Bill Todd The Database Group, Inc.
Concurrency and Transaction Processing. Concurrency models 1. Pessimistic –avoids conflicts by acquiring locks on data that is being read, so no other.
Unit 9 Transaction Processing. Key Concepts Distributed databases and DDBMS Distributed database advantages. Distributed database disadvantages Using.
Module 11 Creating Highly Concurrent SQL Server® 2008 R2 Applications.
Random Logic l Forum.NET l Transaction Isolation Levels Forum.NET Meeting ● Nov
Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools.
Module 6: Data Protection. Overview What does Data Protection include? Protecting data from unauthorized users and authorized users who are trying to.
SQLintersection Understanding Transaction Isolation Levels Randy Knight Wednesday, 3:45-5:00.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
Module 11: Managing Transactions and Locks
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
Module 14: Managing Transactions and Locks. Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
Maciej Pilecki Project Botticelli Ltd. Session Code: DAT402.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Deadlocks 3.0. Final Edition. Everything that developer needs to know Denis Reznik Microsoft SQL Server MVP Director of R&D at Intapp Kyiv.
Does the Optimistic Concurrency resolve your blocking problems Margarita Naumova, SQL Master Academy.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
Read Dirty to Me: SQL Server Isolation Levels Wendy Pastrick Arrow IT Consulting.
Database Transactions  Transaction Management and Concurrency Control.
Transactions in PostgreSQL
Visual Studio 2010 Database Projects
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
Become a Bilingual DBA Oracle for the SQL Server DBA
Transaction Management and Concurrency Control
Let Me Finish... Isolating Write Operations
LAB: Web-scale Data Management on a Cloud
C. Faloutsos Concurrency control - deadlocks
Isolation Levels Understanding Transaction Temper Tantrums
Visual Studio 2010 Database Projects
Let Me Finish... Isolating Write Operations
Working with Very Large Tables Like a Pro in SQL Server 2014
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
Transaction Properties
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Everything you ever wanted to ask but were too shy
මොඩියුල විශ්ලේෂණය Transactions කළමනාකරණය.
Transactions, Locking and Query Optimisation
Understanding Transaction Isolation Levels
On transactions, and Atomic Operations
Let Me Finish... Isolating Write Operations
Batches, Transactions, & Errors
Let Me Finish... Isolating Write Operations
Locks, Blocks, Deadlocks
Transactions and Concurrency
Deadlocks Everything you ever wanted to ask but were too shy
Sioux Falls, SD | Hosted by (605) SQL
A Beginners Guide to Transactions
A Masters view on Locking and blocking
A Beginners Guide to Transactions
About Wolf DBA for over 19 years At RDX for nearly 9
Isolation Levels Understanding Transaction Temper Tantrums
Module 13: Creating Highly Concurrent SQL Server 2012 Applications
Working with Very Large Tables Like a Pro in SQL Server 2017
Temple University – CIS Dept. CIS661 – Principles of Data Management
A Masters view on Locking and blocking
A Masters view on Locking and blocking
Presentation transcript:

SQLintersection Locks, Blocks, and Deadlocks Oh My! Randy Knight Wednesday, 2:15-3:15

© SQLintersection. All rights reserved. Randy Knight  Microsoft Certified Master in SQL Server  20+Years of database experience, focusing on SQL Server since  Worked in a variety of settings, including six years as a Database Architect for match.com  Founder, SQL Solutions Group

© SQLintersection. All rights reserved. Overview  Review  ACID Properties  Transaction Isolation Levels  Defined  Locking  Blocking  Deadlocks  Detection and Prevention  Excessive Blocking  Deadlocks

© SQLintersection. All rights reserved. ACID  Atomic  Consistent  Isolated  Durable

© SQLintersection. All rights reserved. Isolation Levels  ANSI Standard Levels  Level 0: Read Uncommitted  Level 1: Read Committed  Level 2: Repeatable Read  Level 3: Serializable  Snapshot / Versioning

© SQLintersection. All rights reserved. Locking Defined  This is how SQL Server handles Isolation  Read Locks  Shared  Concurrent  Write Locks  Exclusive  Isolated  Lock Levels  Table, Page, Row

© SQLintersection. All rights reserved. Blocking Defined  Definition  User A has a lock on Resource X  User B needs a lock on Resource X  Locks are incompatible  This is a Block  This is normal behavior!  What we care about is EXCESSIVE blocking  Blocking Chains  User A block B, B blocks C, and on and on

Demo Locks and Blocks

© SQLintersection. All rights reserved. Preventing Excessive Blocking  Short transactions  Appropriate Indexes  SNAPSHOT isolation level

© SQLintersection. All rights reserved. Deadlocks Defined  User A and User B both have locks that prevent the other’s transaction from completing  Will never clear itself  SQL server handles automatically  Never normal

© SQLintersection. All rights reserved. Deadlock Detection  Lock Monitor Thread  Every 5 seconds (normally)  Looks at blocks  Can the block clear itself  Cyclic blocks would last forever  Chooses a victim if needed  How is the victim chosen  DEADLOCK_PRIORITY  If they are the same priority, the least expensive transaction to rollback

© SQLintersection. All rights reserved. Viewing Deadlock Information  SQL Server Error Log  Trace Flags  1204  1222  SQL Server Profiler  Extended Events  Already on in the default session  XML is different so doesn’t show up as a deadlock graph

Demo Deadlocks

© SQLintersection. All rights reserved. Common Deadlock Causes  Table Order  Key Lookup  Serializable Isolation Level  Parallelism

© SQLintersection. All rights reserved. Recommendations  Minimize blocking  Short transactions  SNAPSHOT when appropriate  Locking is normal  Blocking is normal  Excessive Blocking is not  Deadlocks are not normal behavior

© SQLintersection. All rights reserved. Review  Review  ACID Properties  Transaction Isolation Levels  Defined  Locking  Blocking  Deadlocks  Detection and Prevention  Excessive Blocking  Deadlocks

© SQLintersection. All rights reserved. References  Forums  MSDN  SQLServerCentral  pluralsight.com  SQL Server: Deadlock Analysis and Prevention  Twitter  #sqlhelp, #sqlblog

Don’t forget to complete an online evaluation on EventBoard! Your evaluation helps organizers build better conferences and helps speakers improve their sessions. Questions? Thank you! Locks, Blocks, and Deadlocks Oh My!