扩展事件的死锁图未显示
Deadlock graph from Extended Events not showing
我有这个查询来自“Sql Server 2017 Query Performance Tuning”(一本书)。可以在此处找到本书的代码:https://github.com/Apress/sql-server-2017-query-perf-tuning
DECLARE @path NVARCHAR(260)
--to retrieve the local path of system_health files
SELECT @path = dosdlc.path
FROM sys.dm_os_server_diagnostics_log_configurations AS dosdlc;
SELECT @path = @path + N'system_health_*';
WITH fxd
AS (SELECT CAST(fx.event_data AS XML) AS Event_Data
FROM sys.fn_xe_file_target_read_file(@path,
NULL,
NULL,
NULL) AS fx )
SELECT dl.deadlockgraph
FROM
( SELECT dl.query('.') AS deadlockgraph
FROM fxd
CROSS APPLY event_data.nodes('(/event/data/value/deadlock)') AS d(dl) ) AS dl;
它应该从扩展事件中捕获死锁图。我刚刚按照这个例子 (How to simulate DEADLOCK on SQL Server?) 生成了一个死锁。
但是当我 运行 查询时,我得到一个空结果集。
您的 XML 路径规范似乎是针对 XE 环形缓冲区目标而不是文件目标。试试下面的查询。
--Get xml_deadlock_report events from system_health session file target
WITH
--get trace folder path and append session name with wildcard (assumes base file name is same as session name)
all_trace_files AS (
SELECT path + '\system_health*.xel' AS FileNamePattern
FROM sys.dm_os_server_diagnostics_log_configurations
)
--get xml_deadlock_report events from all system_health trace files
, deadlock_reports AS (
SELECT CAST(event_data AS xml) AS deadlock_report_xml
FROM all_trace_files
CROSS APPLY sys.fn_xe_file_target_read_file ( FileNamePattern, NULL, NULL, NULL) AS trace_records
WHERE trace_records.object_name like 'xml_deadlock_report'
)
SELECT
deadlock_report_xml.value('(/event/@timestamp)[1]', 'datetime2') AS UtcTimestamp
, deadlock_report_xml AS DeadlockReportXml
FROM deadlock_reports;
要在 SSMS 中查看图形死锁报告,请从 XML 文档的 start/end 中删除 opening/closing event/data/value
标记并另存为扩展名为“ .xdl”。然后在 SSMS 中打开文件以查看死锁图。
我有这个查询来自“Sql Server 2017 Query Performance Tuning”(一本书)。可以在此处找到本书的代码:https://github.com/Apress/sql-server-2017-query-perf-tuning
DECLARE @path NVARCHAR(260)
--to retrieve the local path of system_health files
SELECT @path = dosdlc.path
FROM sys.dm_os_server_diagnostics_log_configurations AS dosdlc;
SELECT @path = @path + N'system_health_*';
WITH fxd
AS (SELECT CAST(fx.event_data AS XML) AS Event_Data
FROM sys.fn_xe_file_target_read_file(@path,
NULL,
NULL,
NULL) AS fx )
SELECT dl.deadlockgraph
FROM
( SELECT dl.query('.') AS deadlockgraph
FROM fxd
CROSS APPLY event_data.nodes('(/event/data/value/deadlock)') AS d(dl) ) AS dl;
它应该从扩展事件中捕获死锁图。我刚刚按照这个例子 (How to simulate DEADLOCK on SQL Server?) 生成了一个死锁。
但是当我 运行 查询时,我得到一个空结果集。
您的 XML 路径规范似乎是针对 XE 环形缓冲区目标而不是文件目标。试试下面的查询。
--Get xml_deadlock_report events from system_health session file target
WITH
--get trace folder path and append session name with wildcard (assumes base file name is same as session name)
all_trace_files AS (
SELECT path + '\system_health*.xel' AS FileNamePattern
FROM sys.dm_os_server_diagnostics_log_configurations
)
--get xml_deadlock_report events from all system_health trace files
, deadlock_reports AS (
SELECT CAST(event_data AS xml) AS deadlock_report_xml
FROM all_trace_files
CROSS APPLY sys.fn_xe_file_target_read_file ( FileNamePattern, NULL, NULL, NULL) AS trace_records
WHERE trace_records.object_name like 'xml_deadlock_report'
)
SELECT
deadlock_report_xml.value('(/event/@timestamp)[1]', 'datetime2') AS UtcTimestamp
, deadlock_report_xml AS DeadlockReportXml
FROM deadlock_reports;
要在 SSMS 中查看图形死锁报告,请从 XML 文档的 start/end 中删除 opening/closing event/data/value
标记并另存为扩展名为“ .xdl”。然后在 SSMS 中打开文件以查看死锁图。