SQL Server 2005 added a new feature called Dynamic Management Views (DMVs) to help DBAs monitor the server. However, people like me who were comfortable using the system tables available in SQL Sever 2000 (read: averse to change 😉 ) took quite a bit of time to switch over to using DMVs. One such DMV that has caught on with making live troubleshooting much easier is the sys.dm_os_ring_buffers DMV. The ring buffers hold historical information about events occurring on the server. Recently, I was working on a lock timeout issue. Based on a profiler trace capture, it was found that the server was experiencing multiple occurrences of the following message:Â
Lock request time out period exceeded. Â
We identified the statements and made the changes to prevent the Lock Timeout from occurring. Now that the server was being monitored, I didn’t want to a run a SQL Server profiler trace to track the occurrence of this message. So, I thought of using the Ring Buffers DMV to monitor if any further Lock Timeouts were occurring the server. This made monitoring the instance a piece of cake!Â
The script below will give you the time range between which the exceptions are stored in the Ring Buffers along with the list of exception occurrences that you want to monitor.Â
SQL Server 2005Â
------------- Script Start ----------------------- DECLARE @ts_now BIGINT,@dt_max BIGINT, @dt_min BIGINT SELECT @ts_now = cpu_ticks / CONVERT(FLOAT, cpu_ticks_in_ms) FROM sys.dm_os_sys_info select @dt_max = MAX(timestamp), @dt_min = MIN(timestamp) from sys.dm_os_ring_buffers WHERE ring_buffer_type = N'RING_BUFFER_EXCEPTION' select DATEADD(ms, -1 * (@ts_now - @dt_max), GETDATE()) AS MaxTime, DATEADD(ms, -1 * (@ts_now - @dt_min), GETDATE()) AS MinTime SELECT record_id, DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS EventTime,y.Error,UserDefined,b.description as NormalizedText FROM ( SELECT                        record.value('(./Record/@id)[1]', 'int') AS record_id,                        record.value('(./Record/Exception/Error)[1]', 'int') AS Error,                        record.value('(./Record/Exception/UserDefined)[1]', 'int') AS UserDefined,TIMESTAMP FROM ( SELECT TIMESTAMP, CONVERT(XML, record) AS record FROM sys.dm_os_ring_buffers WHERE ring_buffer_type = N'RING_BUFFER_EXCEPTION' AND record LIKE '% %') AS x) AS y INNER JOIN sys.sysmessages b on y.Error = b.error WHERE b.msglangid = 1033 and y.Error = 1222 -- Change the message number to the message number that you want to monitor ORDER BY record_id DESC ------------- Script End -----------------------
Â
SQL Server 2008Â
------------- Script Start ----------------------- DECLARE @ts_now BIGINT,@dt_max BIGINT, @dt_min BIGINT SELECT @ts_now = cpu_ticks / CONVERT(FLOAT, ms_ticks) FROM sys.dm_os_sys_info select @dt_max = MAX(timestamp), @dt_min = MIN(timestamp) from sys.dm_os_ring_buffers WHERE ring_buffer_type = N'RING_BUFFER_EXCEPTION' select DATEADD(ms, -1 * (@ts_now - @dt_max), GETDATE()) AS MaxTime, DATEADD(ms, -1 * (@ts_now - @dt_min), GETDATE()) AS MinTime SELECT record_id, DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS EventTime,Error,UserDefined,text as NormalizedText FROM ( SELECT                        record.value('(./Record/@id)[1]', 'int') AS record_id,                        record.value('(./Record/Exception/Error)[1]', 'int') AS Error,                        record.value('(./Record/Exception/UserDefined)[1]', 'int') AS UserDefined,TIMESTAMP FROM ( SELECT TIMESTAMP, CONVERT(XML, record) AS record FROM sys.dm_os_ring_buffers WHERE ring_buffer_type = N'RING_BUFFER_EXCEPTION' AND record LIKE '% %') AS x) AS y INNER JOIN sys.messages b on y.Error = b.message_id WHERE b.language_id = 1033 and y.Error = 1222 -- Change the message number to the message number that you want to monitor ORDER BY record_id DESC ------------- Script End -----------------------
Â