r/SQLServer • u/Kenn_35edy • 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
•
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?
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.
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.
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.NameAS 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.nameas TransactionName,CN.auth_scheme as AuthenticationMethodFROM sys.dm_tran_locks LJOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_idJOIN sys.objects O ON O.object_id = P.object_idJOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_idJOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_idJOIN sys.dm_tran_active_transactions AT ON TST.transaction_id = AT.transaction_idJOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_idCROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) AS STWHERE resource_database_id = db_id()ORDER BY L.request_session_id2
u/jshine13371 6 Oct 21 '25
Not sure what you mean by this, but
sp_WhoIsActiveis the simplest solution.2
u/stilllost12 Oct 22 '25
Set up some extended events https://www.sqlskills.com/blogs/erin/capture-blocking-information-with-extended-events-and-the-blocked-process-report/
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