我使用从 Kimberly Tripp 的 SQL Server 2008 Internals 书中获得的脚本创建了以下事件会话。它已被修改为发送到文件而不是环形缓冲区。
CREATE EVENT SESSION
[statement_completed_file]
ON SERVER
ADD EVENT
sqlserver.sp_statement_completed,
ADD EVENT
sqlserver.sql_statement_completed
(
ACTION
(
sqlserver.sql_text
)
WHERE
(
sqlserver.session_id=53
)
)
ADD TARGET package0.asynchronous_file_target
(
set filename=N'C:\MSSQL\TEMP\stats.xel',
metadatafile=N'C:\MSSQL\TEMP\stats.xem'
)
WITH
(
MAX_MEMORY=4096KB,
EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,
MAX_DISPATCH_LATENCY=1 SECONDS,
TRACK_CAUSALITY=OFF,
STARTUP_STATE=OFF
)
这是查询数据的原始脚本。
SELECT
theNodes.event_data.value('(data/value)[1]', 'bigint') AS source_database_id,
theNodes.event_data.value('(data/value)[2]', 'bigint') AS object_id,
theNodes.event_data.value('(data/value)[3]', 'bigint') AS object_type,
theNodes.event_data.value('(data/value)[4]', 'bigint') AS cpu,
theNodes.event_data.value('(data/value)[5]', 'bigint') AS duration,
theNodes.event_data.value('(data/value)[6]', 'bigint') AS reads,
theNodes.event_data.value('(data/value)[7]', 'bigint') AS writes,
theNodes.event_data.value('(action/value)[1]', 'nvarchar(max)') AS sql_text
FROM
(
SELECT
CONVERT(XML, st.target_data) AS ring_buffer
FROM sys.dm_xe_sessions s
JOIN sys.dm_xe_session_targets st ON s.address = st.event_session_address
WHERE s.name = 'statement_completed'
) AS theData
CROSS APPLY
theData.ring_buffer.nodes('//RingBufferTarget/event') theNodes (event_data)
WHERE theNodes.event_data.value('(action/value)[1]', 'nvarchar(max)') is not null
我如何修改它以从两个文件 xel 和 xem 而不是环形缓冲区中读取。我一直在谷歌上搜索,但学习曲线很粗糙。预先感谢您的帮助。
试试这个例子:
这是另一个查询