Last active
November 15, 2022 02:19
-
-
Save EitanBlumin/d47a297608b677a0b0a3bf90253a0b8c to your computer and use it in GitHub Desktop.
Get Deadlock Trace Info from Default Trace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @FileName NVARCHAR(250) | |
select @FileName = REPLACE(c.column_value, '.xel', '*.xel') | |
from sys.dm_xe_sessions s | |
JOIN sys.dm_xe_session_object_columns c | |
ON s.address =c.event_session_address | |
WHERE column_name = 'filename' | |
AND s.name = 'system_health' | |
SELECT | |
CAST (event_data AS XML).value('(event/@timestamp)[1]','DATETIME') AS event_timestamp | |
, CAST (event_data AS XML).query('(event/data[@name="xml_report"]/value/deadlock)[1]') AS deadlock_graph | |
FROM sys.fn_xe_file_target_read_file (@FileName,null,null, null) | |
WHERE object_name like '%deadlock%' | |
ORDER BY 1 DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @filename nvarchar(200) | |
select @filename = convert(nvarchar(200), value) | |
from ::fn_trace_getinfo(null) | |
where property = 2 | |
and convert(nvarchar(200), value) LIKE '%deadlocks%' | |
PRINT @filename | |
select StartTime, convert(xml, TextData) AS Deadlock_Graph, ServerName | |
from ::fn_trace_gettable(@filename,default) | |
WHERE TextData IS NOT NULL | |
order by 1 desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment