標籤:緩衝區 環形緩衝區 exception
SQL Server 環形緩衝區(Ring Buffer) -- RING_BUFFER_EXCEPTION 跟蹤異常
動態管理檢視sys.dm_os_ring_buffers使得即時定位問題更加容易。環形緩衝包含大量的在伺服器上發生的事件。當前,我正碰到鎖請求逾時問題。根據SQL Server Profiler跟蹤捕獲,探索服務器收到大量如下資訊:
Lock request time out period exceeded.
我們找到了語句並修改,來阻止所請求逾時的發生。現在伺服器正被監控,我不想運行SQL Server Profiler去跟蹤這個訊息的產生。所以,我想用環形緩衝動態管理檢視去監控是否伺服器上有進一步的鎖請求逾時發生。這使得監控執行個體更容易。
下面的指令碼給出了一個儲存在環形緩衝區中的異常的時間範圍,輸出了大量的發生的異常。
對於SQL Server 2005:
DECLARE @ts_now BIGINT,@dt_max BIGINT, @dt_min BIGINTSELECT @ts_now = cpu_ticks / CONVERT(FLOAT, cpu_ticks_in_ms) FROM sys.dm_os_sys_infoselect @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 MinTimeSELECT record_id,DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS EventTime,y.Error,UserDefined,b.description as NormalizedTextFROM (SELECTrecord.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,TIMESTAMPFROM (SELECT TIMESTAMP, CONVERT(XML, record) AS recordFROM sys.dm_os_ring_buffersWHERE ring_buffer_type = N‘RING_BUFFER_EXCEPTION‘AND record LIKE ‘% %‘) AS x) AS yINNER JOIN sys.sysmessages bon y.Error = b.errorWHERE b.msglangid = 1033 and y.Error = 1222 -- Change the message number to the message number that you want to monitorORDER BY record_id DESC
對於SQL Server 2008:
DECLARE @ts_now BIGINT,@dt_max BIGINT, @dt_min BIGINTSELECT @ts_now = cpu_ticks/(cpu_ticks/ms_ticks) FROM sys.dm_os_sys_infoselect @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 MinTimeSELECT record_id,DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS EventTime,Error,UserDefined,text as NormalizedTextFROM (SELECTrecord.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,TIMESTAMPFROM (SELECT TIMESTAMP, CONVERT(XML, record) AS recordFROM sys.dm_os_ring_buffersWHERE ring_buffer_type = N‘RING_BUFFER_EXCEPTION‘AND record LIKE ‘% %‘) AS x) AS yINNER JOIN sys.messages bon y.Error = b.message_idWHERE b.language_id = 1033 and y.Error = 1222 -- Change the message number to the message number that you want to monitorORDER BY record_id DESC
650) this.width=650;" title="clip_image001" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" alt="clip_image001" src="http://s3.51cto.com/wyfs02/M02/54/1A/wKioL1R4Ip-A0rz4AAIdJYZV5Ts779.jpg" height="243" border="0" />
650) this.width=650;" title="clip_image002" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" alt="clip_image002" src="http://s3.51cto.com/wyfs02/M00/54/1A/wKioL1R4Ip_yGH0fAAA_b8BoxUE753.jpg" height="70" border="0" />
本文出自 “滴水石穿” 部落格,請務必保留此出處http://ultrasql.blog.51cto.com/9591438/1584028
SQL Server 環形緩衝區(Ring Buffer) -- RING_BUFFER_EXCEPTION 跟蹤異常