What is Blocking on SQL Server?
Blocking in SQL Server happens when one transaction acquires a lock on a database resource, such as a row, page, or table, preventing another transaction from accessing that same resource until the lock is released. This creates a situation where the second transaction must wait, causing a delay in its execution. Blocking is a normal part of SQL Server’s concurrency control, which uses locks to ensure data consistency, but excessive or prolonged blocking can lead to performance issues.
Why Does Blocking Happen?
Blocking occurs due to several common factors that affect how transactions interact with database resources. These include:
- Long-Running Transactions: Transactions that take a long time to complete hold locks for extended periods, increasing the likelihood that other transactions will be forced to wait.
- Excessive Locking: When transactions use overly restrictive locks, such as table locks instead of more granular row or page locks, they block more resources than necessary, impacting other transactions.
- Poorly Optimized Queries: Queries that scan large portions of a table, lack proper indexes, or are inefficiently written can hold locks longer than needed, causing delays for other operations.
These issues are often exacerbated in high-concurrency environments where multiple transactions compete for the same resources simultaneously.
A Real-World Example of Blocking
Consider a busy website with over 10,000 active users, relying on SQL Server as its database backend. Imagine a scenario where an update query is running to modify user data in a table. This query acquires a lock on the affected rows or table and takes 30 seconds to complete due to its complexity or lack of optimization. During this time, a login query, which needs to read data from the same table, is submitted by another user. The login query cannot proceed because it is blocked by the update query’s lock, causing the website’s login process to stall for 30 seconds.
This delay manifests as slow performance for the end user, who may experience a sluggish or unresponsive application. Eventually, when the update query completes and releases its locks, the login query can proceed, and the application resumes normal operation. While blocking resolves on its own once locks are released, frequent or prolonged blocking can significantly degrade user experience and system performance.
Mitigating Blocking in SQL Server
To reduce blocking and improve SQL Server Performance, consider the following strategies:
- Optimize Queries: Write efficient queries and ensure proper indexing to minimize the scope and duration of locks.
- Shorten Transactions: Keep transactions as brief as possible by reducing unnecessary operations and committing changes promptly.
- Use Appropriate Lock Granularity: Encourage row-level locking when possible, rather than table-level locks, to reduce the number of blocked resources.
- Adjust Isolation Levels: Use less restrictive transaction isolation levels, such as Read Committed Snapshot Isolation, to reduce lock contention, though this requires careful consideration of data consistency needs.
- Monitor Blocking: Use SQL Server tools like Dynamic Management Views (DMVs) or SQL Server Profiler to identify and analyze blocking events, helping to pinpoint problematic queries or transactions.
By addressing the root causes of blocking and implementing these best practices, database administrators and developers can minimize its impact, ensuring smoother and more responsive SQL Server Performance, especially in high-traffic applications.
Have you seen our podcast episode where we talk about blocking at Deadlocks? Stedman SQL Podcast Season 2 Episode 13.
Do you need help with deaclocks on your SQL Server? We can help you root out those deadlock and blocking issues with a performance assessment.
SQL Server Performance Assessment
Identify the root causes of performance issues, blocking and deadlocks with our comprehensive assessment. Details at https://stedmansolutions.com/services/sql-performance-tuning/.
More from Stedman Solutions:
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

