r/SQLServer • • Oct 21 '25

Question how to capture current Blocking query

Hi I need query where i can captured current/running blocking query with name of root blocker sp and its part which is catually bloking , sp and query begin blockved...I know googel is ans but its not giving any good solution .if any body has any script of link to it which gives all info apart form above which i requested then do share

I know about sp_whoisactive , but sometimes it fails giving error of loops or joins .i have not captured its image or i may have shared it here ....

Regrads

9 Upvotes

13 comments sorted by

•

u/AutoModerator Oct 21 '25

After your question has been solved /u/Kenn_35edy, please reply to the helpful user's comment with the phrase "Solution verified".

This will not only award a point to the contributor for their assistance but also update the post's flair to "Solved".


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

10

u/VladDBA ‪ ‪Microsoft MVP ‪ ‪ Oct 21 '25

Have you tried sp_BlitzWho from Brent Ozar's First Responder Toolkit?

1

u/Kenn_35edy Oct 21 '25

Nope but will run and let you know ..is it's for currently running +blocking ?

→ More replies (1)

6

u/wiseDATAman Oct 21 '25

sp_BlitzWho or sp_WhoIsActive if you need something to do this interactively. If you want to capture it automatically, DBA Dash has excellent blocking reporting. Running Queries in DBA Dash is similar to sp_WhoIsActive or sp_BlitzWho but optimized for regular collection & has the advantage of being able to improve the display with a custom GUI. It will highlight the root blocker as well as show the full blocking chain. DBA Dash is a free and open source monitoring tool I created.

Note: You can also schedule sp_WhoIsActive and sp_BlitzWho to log to a table, though they are optimized for interactive use.

→ More replies (1)

4

u/perry147 Oct 21 '25

Sp_who will show the current blocking spid. There is also an sp_who2 that shows even more details, but you will need to download and run to install it.

2

u/jwk6 Oct 22 '25

Both of these are system stored procedures built into SQL Server since at least SQL Server 6.5.

There are many other tools like sp_whoisactive and sp_blitzwho that must be downloaded and deployed.

3

u/SirGreybush 1 Oct 21 '25

In conjuction with SP_WHO, I also run this that will show any transaction locks. If no rows, no active locks. A lock on a table can block certain queries that are waiting on the data to have the very latest.

SELECT L.request_session_id AS SPID,

DB_NAME(L.resource_database_id) AS DatabaseName,

O.Name AS LockedObjectName,

P.object_id AS LockedObjectId,

L.resource_type AS LockedResource,

L.request_mode AS LockType,

ST.text AS SqlStatementText,

ES.login_name AS LoginName,

ES.host_name AS HostName,

TST.is_user_transaction as IsUserTransaction,

AT.name as TransactionName,

CN.auth_scheme as AuthenticationMethod

FROM sys.dm_tran_locks L

JOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_id

JOIN sys.objects O ON O.object_id = P.object_id

JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id

JOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_id

JOIN sys.dm_tran_active_transactions AT ON TST.transaction_id = AT.transaction_id

JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id

CROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) AS ST

WHERE resource_database_id = db_id()

ORDER BY L.request_session_id

2

u/jshine13371 6 Oct 21 '25

I know about sp_whoisactive , but sometimes it fails giving error of loops or joins

Not sure what you mean by this, but sp_WhoIsActive is the simplest solution.

1

u/FreedToRoam Oct 24 '25

Sp_who2 to find the blocking spid number and then Dbcc inputbuffer(spidnumber) to get the content of the sql code