Reader small image

You're reading from  Learn T-SQL Querying - Second Edition

Product typeBook
Published inFeb 2024
PublisherPackt
ISBN-139781837638994
Edition2nd Edition
Right arrow
Authors (2):
Pedro Lopes
Pedro Lopes
author image
Pedro Lopes

Pedro Lopes is a Program Manager in the Database Systems group, based in Redmond, WA, USA. He has over 19 years of industry experience and has been with Microsoft for 9 years. He is currently responsible for program management of Database Engine features for in-market and vNext versions of SQL Server, with a special focus on the Relational Engine. He has extensive experience with query performance troubleshooting and is a regular speaker at numerous conferences such as SQLBits, PASS Summit, SQLIntersection, Microsoft Ignite, and Microsoft Build. He blogs about SQL on the SQL Server Team blog. He has authored several tools in the Tiger toolbox on GitHub: AdaptiveIndexDefrag maintenance solution, BPCheck, and usp_WhatsUp.
Read more about Pedro Lopes

Pam Lahoud
Pam Lahoud
author image
Pam Lahoud

Pam Lahoud is a Program Manager in the Database Systems group, based in Redmond, WA, USA. She has been with Microsoft for 13 years and is currently responsible for program management of Database Engine features for in-market and vNext versions of SQL Server, with a special focus on the Storage Engine area. She is passionate about SQL Server performance and has focused on performance tuning and optimization, particularly from the developer's perspective, throughout her career. She is a SQL Server 2008 Microsoft Certified Master (MCM) with over 20 years of experience working with SQL Server.
Read more about Pam Lahoud

View More author details
Right arrow

Investigating blocking

Blocking is a very common scenario in many database systems. This is what happens when one query holds exclusive access to a resource that another query also requires. It is normal for some blocking to occur, but severe blocking can cause major performance issues and should be investigated. When troubleshooting query performance, it’s a good idea to check for blocking first to see if queries are slow because they are expensive, or because they are being blocked by some other workload.

The key DMVs for investigating blocking are sys.dm_exec_requests and sys.dm_os_waiting_tasks. As we discussed previously, these DMVs show us which queries are currently running and what state they are in. They also have columns that will indicate which sessions may be causing blocking.

The following example shows a simple query that can be used to look for blocking on the system:

SELECT s.session_id, s.last_request_end_time, ISNULL(r.status,s.status) AS status, s...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learn T-SQL Querying - Second Edition
Published in: Feb 2024Publisher: PacktISBN-13: 9781837638994

Authors (2)

author image
Pedro Lopes

Pedro Lopes is a Program Manager in the Database Systems group, based in Redmond, WA, USA. He has over 19 years of industry experience and has been with Microsoft for 9 years. He is currently responsible for program management of Database Engine features for in-market and vNext versions of SQL Server, with a special focus on the Relational Engine. He has extensive experience with query performance troubleshooting and is a regular speaker at numerous conferences such as SQLBits, PASS Summit, SQLIntersection, Microsoft Ignite, and Microsoft Build. He blogs about SQL on the SQL Server Team blog. He has authored several tools in the Tiger toolbox on GitHub: AdaptiveIndexDefrag maintenance solution, BPCheck, and usp_WhatsUp.
Read more about Pedro Lopes

author image
Pam Lahoud

Pam Lahoud is a Program Manager in the Database Systems group, based in Redmond, WA, USA. She has been with Microsoft for 13 years and is currently responsible for program management of Database Engine features for in-market and vNext versions of SQL Server, with a special focus on the Storage Engine area. She is passionate about SQL Server performance and has focused on performance tuning and optimization, particularly from the developer's perspective, throughout her career. She is a SQL Server 2008 Microsoft Certified Master (MCM) with over 20 years of experience working with SQL Server.
Read more about Pam Lahoud