sql server 环形缓冲区(ring buffer) -- ring buffer connectivity 的深入理解 首先我们从连接的ring buffer数据返回的xml来入手。 selectcast(recordasxml)asrecord_datafromsys.dm_os_ring_bufferswherering_buffer_type='ring_buffer_connectivity' 执
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=max-width:90% alt=clip_image001[6] src=http://www.68idc.cn/help/uploads/allimg/151111/121pv918-0.jpg style=max-width:90% border=0 />
点击xml的超链接,打开文件内容看到更可读的内容,包括一条基本的ring buffer连接error记录。
650) this.width=650; title=clip_image002[6] style=max-width:90% alt=clip_image002[6] src=http://www.68idc.cn/help/uploads/allimg/151111/121ps335-1.jpg style=max-width:90% 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=max-width:90% alt=clip_image003[6] src=http://www.68idc.cn/help/uploads/allimg/151111/121pq442-2.jpg style=max-width:90% border=0>