Recentemente precisei descobrir bloqueio de processos no SQL Server de uma forma prática e simples. Na base de conhecimento onde fica todos os scripts que compartilhamos no grupo de DBA SQL Server, encontrei um script que faz exatamente o que estava procurando, sendo assim resolvi compartilhar aqui com vocês o script. Segue abaixo:
SET NOCOUNT ON GO SELECT SPID, BLOCKED, REPLACE (REPLACE (T.TEXT, CHAR(10), ' '), CHAR (13), ' ' ) AS BATCH INTO #T FROM sys.sysprocesses R CROSS APPLY sys.dm_exec_sql_text(R.SQL_HANDLE) T GO WITH BLOCKERS (SPID, BLOCKED, LEVEL, BATCH) AS ( SELECT SPID, BLOCKED, CAST (REPLICATE ('0', 4-LEN (CAST (SPID AS VARCHAR))) + CAST (SPID AS VARCHAR) AS VARCHAR (1000)) AS LEVEL, BATCH FROM #T R WHERE (BLOCKED = 0 OR BLOCKED = SPID) AND EXISTS (SELECT * FROM #T R2 WHERE R2.BLOCKED = R.SPID AND R2.BLOCKED <> R2.SPID) UNION ALL SELECT R.SPID, R.BLOCKED, CAST (BLOCKERS.LEVEL + RIGHT (CAST ((1000 + R.SPID) AS VARCHAR (100)), 4) AS VARCHAR (1000)) AS LEVEL, R.BATCH FROM #T AS R INNER JOIN BLOCKERS ON R.BLOCKED = BLOCKERS.SPID WHERE R.BLOCKED > 0 AND R.BLOCKED <> R.SPID ) SELECT N' ' + REPLICATE (N'| ', LEN (LEVEL)/4 - 1) + CASE WHEN (LEN(LEVEL)/4 - 1) = 0 THEN 'HEAD - ' ELSE '|------ ' END + CAST (SPID AS NVARCHAR (10)) + N' ' + BATCH AS BLOCKING_TREE FROM BLOCKERS ORDER BY LEVEL ASC GO DROP TABLE #T GO
Ao executar o script vocês poderão encontrar na primeira linha quem é a sessão principal que está bloqueando as outras sessões, chamada HEAD. Além disso você também terá acesso a query que está sendo executado por essa sessão.
Blackjack, additionally known as twenty-one, is just one of one of the most popular gambling…
If you are a fan of online gambling, then you must have come across gry…
On the internet online casinos have transformed the betting industry, enabling players to vegas.hu online…
Casinos online offer free spins to draw new customers. These bonuses are usually very profitable,…
In recent times, online casino sites have actually obtained enormous appeal among gamers, providing a…
Bitcoin, the most preferred cryptocurrency worldwide, has reinvented lots of industries, including the on baixar…