read from extended events written to ring buffer

SELECT CAST(target_data as xml) AS targetdata
INTO #capture_waits_data
FROM sys.dm_xe_session_targets xet
JOIN sys.dm_xe_sessions xes
ON xes.address = xet.event_session_address
WHERE = ‘xeventname’
AND xet.target_name = ‘ring_buffer’;

xed.event_data.value(‘(action[@name=”username”]/value)[1]’, ‘varchar(100)’) AS username,
xed.event_data.value(‘(action[@name=”database_name”]/value)[1]’, ‘varchar(100)’) AS dbname,
xed.event_data.value(‘(data[@name=”statement”]/value)[1]’, ‘varchar(max)’) AS statement,
xed.event_data.value(‘(action[@name=”collect_system_time”]/value)[1]’, ‘datetime’) AS date
FROM #capture_waits_data
CROSS APPLY targetdata.nodes(‘//RingBufferTarget/event’) AS xed (event_data);

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.