ホームページ >データベース >mysql チュートリアル > SQL Server 环形缓冲区(Ring Buffer) -- RING BUFFER CONNECTIVITY 的
SQLServer环形缓冲区(RingBuffer)--RINGBUFFERCONNECTIVITY的深入理解首先我们从连接的RingBuffer数据返回的XML来入手。SELECTCAST(recordasxml)ASrecord_data
SQL Server 环形缓冲区(Ring Buffer) -- RING BUFFER CONNECTIVITY 的深入理解
首先我们从连接的Ring Buffer数据返回的XML来入手。
SELECT CAST(record as xml) AS record_data FROM sys.dm_os_ring_buffers WHERE ring_buffer_type= 'RING_BUFFER_CONNECTIVITY'
执行上面的语句,得到下面的结果:
点击XML的超链接,打开文件内容看到更可读的内容,包括一条基本的Ring Buffer连接Error记录。
可以看到在XML文档中有许多相当有用的信息。像SniConsumerError,State和RemoteHost这些。
特别注意的是,RecordType节点,对于我们上面的截图来看标识为“Error”,说明是连接错误信息。为了识别这种类型的连接Ring Buffer,我们可以查询SniConsumerError代码号,准确定位是什么错误导致的。
RecordType包含那些值?
1. Error – 连接错误
2. LoginTimers – 连接超时
3. ConnectionClose – 杀掉进程
可以通过如下脚本,,将XML数据转化为可读信息:
;WITH RingBufferConnectivity as ( SELECT records.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_data FROM sys.dm_os_ring_buffers WHERE ring_buffer_type= 'RING_BUFFER_CONNECTIVITY' ) TabA CROSS APPLY record_data.nodes('//Record') AS records (record) ) SELECT RBC.*, m.text FROM RingBufferConnectivity RBC LEFT JOIN sys.messages M ON RBC.Error = M.message_id AND M.language_id = 1033 WHERE RBC.RecordType='Error' --Comment Out to see all RecordTypes ORDER BY RBC.RecordTime DESC
执行上面的查询后,将得到下面的可读结果。在这个查询中,我们关联Ring Buffer数据和sys.messages视图去抓取Error id的文本。通过这个信息我们可以跟踪到精确的导致Error:Login失败的信息。
本文出自 “滴水石穿” 博客,请务必保留此出处