Skip to content

Commit 60958d1

Browse files
committed
replace/rewrite
1 parent 349f75b commit 60958d1

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

deadlocks in xevents.sql

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
2-
3-
declare @xml xml
4-
select @xml = CAST(t.target_data as xml)
5-
from sys.dm_xe_session_targets t
6-
inner join sys.dm_xe_sessions s
7-
on s.address = t.event_session_address
8-
where s.name = 'system_health'
9-
and t.target_name = 'ring_buffer'
10-
select @xml.query('/RingBufferTarget/event [@name="xml_deadlock_report"]')
11-
FOR XML PATH ('XEvent')
12-
13-
go
1+
--deadlocks in XEvents
2+
--updated 20171003 WDA
3+
4+
5+
WITH cteDeadlocks ([Deadlock_XML]) AS (
6+
--Query RingBufferTarget
7+
SELECT [Deadlock_XML] = CAST(target_data AS XML)
8+
FROM sys.dm_xe_sessions AS xs
9+
INNER JOIN sys.dm_xe_session_targets AS xst
10+
ON xs.address = xst.event_session_address
11+
WHERE xs.NAME = 'system_health'
12+
AND xst.target_name = 'ring_buffer'
13+
)
14+
SELECT
15+
Deadlock_XML = x.Graph.query('(event/data/value/deadlock)[1]') --View as XML for detail, save this output as .xdl and re-open in SSMS for visual graph
16+
, Occured = x.Graph.value('(event/data/value/deadlock/process-list/process/@lastbatchstarted)[1]', 'datetime2(3)') --date the last batch in the first process started, only an approximation of time of deadlock
17+
, DB = DB_Name(x.Graph.value('(event/data/value/deadlock/process-list/process/@currentdb)[1]', 'int')) --Current database of the first listed process
18+
FROM (
19+
SELECT Graph.query('.') AS Graph
20+
FROM cteDeadLocks c
21+
CROSS APPLY c.[Deadlock_XML].nodes('RingBufferTarget/event[@name="xml_deadlock_report"]') AS Deadlock_Report(Graph)
22+
) AS x
23+
ORDER BY Occured desc
1424

1525

1626

0 commit comments

Comments
 (0)