concept blocking in category sql

appears as: blocking, blocking
SQL Server DMVs in Action: Better Queries with Dynamic Management Views

This is an excerpt from Manning's book SQL Server DMVs in Action: Better Queries with Dynamic Management Views.

The first two grids show the root-blocking spid (this is the cause of the blocking) and the blocked spid. This is followed by a grid showing the date and time the blocking occurred. Finally, details of everything that’s currently running are shown; these include the individual line of SQL that’s running together with the parent query (stored procedure or batch).

Each SQL query, even a simple SELECT, takes out locks on various structures within the database (we’ll discuss these structures shortly). By grouping queries within a transaction, we typically increase the amount and scope of these locks, resulting in potentially more blocking, decreased performance (of the other queries), and less concurrency. Toward the end of this chapter we’ll examine ways in which these locks and blocking can be reduced, with a view to allowing greater concurrency, performance, and scalability while balancing any reduction in data consistency.

Often the terms blocking and waiting are used interchangeably. Blocking is a specific type of waiting that relates to locks. Blocking is a subset of waiting.

By default, SQL Server will wait until the blocking has finished before proceeding. If the client is a Windows or web client, the blocked query typically waits a given time before failing with a timeout error.

It’s also possible to record blocking that occurs for longer than a given time period by setting the blocked process threshold within the system configuration. This enables SQL Profiler to record details of any blocks that occur over the given wait threshold.