標籤:ringbuffer 緩衝區 環形緩衝區
SQL Server 環形緩衝區(Ring Buffer) -- RING BUFFER CONNECTIVITY 的深入理解
首先我們從串連的Ring Buffer資料返回的XML來入手。
SELECT CAST(record as xml) AS record_dataFROM sys.dm_os_ring_buffersWHERE ring_buffer_type= ‘RING_BUFFER_CONNECTIVITY‘
執行上面的語句,得到下面的結果:
650) this.width=650;" title="clip_image001[6]" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" alt="clip_image001[6]" src="http://s3.51cto.com/wyfs02/M02/54/11/wKioL1R29lfS1f5MAAOmR_wPPsE646.jpg" height="213" border="0" />
點擊XML的超連結,開啟檔案內容看到更可讀的內容,包括一條基本的Ring Buffer串連Error記錄。
650) this.width=650;" title="clip_image002[6]" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" alt="clip_image002[6]" src="http://s3.51cto.com/wyfs02/M00/54/11/wKioL1R29lnRPuB4AAQBFx6856c856.jpg" height="516" border="0" />
可以看到在XML文檔中有許多相當有用的資訊。像SniConsumerError,State和RemoteHost這些。
特別注意的是,RecordType節點,對於我們上面的來看標識為“Error”,說明是串連錯誤資訊。為了識別這種類型的串連Ring Buffer,我們可以查詢SniConsumerError代碼號,準確定位是什麼錯誤導致的。
RecordType包含那些值?
1. Error – 串連錯誤
2. LoginTimers – 連線逾時
3. ConnectionClose – 殺掉進程
可以通過如下指令碼,將XML資料轉化為可讀資訊:
;WITH RingBufferConnectivity as( SELECTrecords.record.value(‘(/Record/@id)[1]‘, ‘int‘) AS [RecordID],records.record.value(‘(/Record/ConnectivityTraceRecord/RecordType)[1]‘, ‘varchar(max)‘) AS [RecordType],records.record.value(‘(/Record/ConnectivityTraceRecord/RecordTime)[1]‘, ‘datetime‘) AS [RecordTime],records.record.value(‘(/Record/ConnectivityTraceRecord/SniConsumerError)[1]‘, ‘int‘) AS [Error],records.record.value(‘(/Record/ConnectivityTraceRecord/State)[1]‘, ‘int‘) AS [State],records.record.value(‘(/Record/ConnectivityTraceRecord/Spid)[1]‘, ‘int‘) AS [Spid],records.record.value(‘(/Record/ConnectivityTraceRecord/RemoteHost)[1]‘, ‘varchar(max)‘) AS [RemoteHost],records.record.value(‘(/Record/ConnectivityTraceRecord/RemotePort)[1]‘, ‘varchar(max)‘) AS [RemotePort],records.record.value(‘(/Record/ConnectivityTraceRecord/LocalHost)[1]‘, ‘varchar(max)‘) AS [LocalHost]FROM( SELECT CAST(record as xml) AS record_dataFROM sys.dm_os_ring_buffersWHERE ring_buffer_type= ‘RING_BUFFER_CONNECTIVITY‘) TabACROSS APPLY record_data.nodes(‘//Record‘) AS records (record))SELECT RBC.*, m.textFROM RingBufferConnectivity RBCLEFT JOIN sys.messages M ONRBC.Error = M.message_id AND M.language_id = 1033WHERE RBC.RecordType=‘Error‘ --Comment Out to see all RecordTypesORDER BY RBC.RecordTime DESC
執行上面的查詢後,將得到下面的可讀結果。在這個查詢中,我們關聯Ring Buffer資料和sys.messages視圖去抓取Error id的文本。通過這個資訊我們可以跟蹤到精確的導致Error:Login失敗的資訊。
650) this.width=650;" title="clip_image003[6]" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" alt="clip_image003[6]" src="http://s3.51cto.com/wyfs02/M00/54/11/wKioL1R29lrzAjH4AAMmbdEMNQ0680.jpg" height="201" border="0" />
本文出自 “滴水石穿” 部落格,請務必保留此出處http://ultrasql.blog.51cto.com/9591438/1583446
SQL Server 環形緩衝區(Ring Buffer) -- RING BUFFER CONNECTIVITY 的深入理解