您好,登錄后才能下訂單哦!
連接超時(shí)
對(duì)于連接超時(shí),首先可以查看Connectivity Ring Buffer中的LoginTimers類型錯(cuò)誤來(lái)分析,如果想獲得更詳盡的信息,再通過(guò)抓包工具network monitor。
具體方法和語(yǔ)句可參考以下文章:
https://blogs.msdn.microsoft.com/apgcdsd/2011/11/20/ring-buffersql-server-2008/
http://ultrasql.blog.51cto.com/9591438/1583446
查詢超時(shí)
對(duì)于查詢超時(shí),針對(duì)SQL Server 2012以下的版本,使用Profiler的TSQL_Duration模板的基礎(chǔ)上,添加“Errors and Warnings”下的“Attention”,根據(jù)捕獲到的Attention結(jié)合上下文去查找相應(yīng)的語(yǔ)句;對(duì)于SQL Server 2012及以上版本,直接使用擴(kuò)展事件監(jiān)控sqlserver.attention事件,直接輸出sql_text。
以下為XE腳本:
use tempdb go if exists (select * from sys.objects where name = 'sqlws_xev_attention') drop view sqlws_xev_attention go create view sqlws_xev_attention as with xevents (event_data) as ( select event.query('.') as event_data from ((select cast (xest.target_data as xml) as target_data from sys.dm_xe_sessions as xes inner join sys.dm_xe_session_targets as xest on (xes.address = xest.event_session_address) where xes.name = 'sqlws_xevents_attention' and xest.target_name = 'ring_buffer') as td cross apply target_data.nodes ('//event[@name="attention"]') as x (event)) ) select event_data.value ('(event/@name)[1]', 'varchar(max)') as event_name, event_data.value ('(event/@timestamp)[1]', 'datetime') as event_timestamp, event_data.value ('(event/data[@name="duration"]/value)[1]', 'bigint') as [duration], event_data.value ('(event/data[@name="request_id"]/value)[1]', 'int') as [request_id], event_data.value ('(event/action[@name="client_app_name"]/value)[1]', 'nvarchar(max)') as action_client_app_name, event_data.value ('(event/action[@name="client_hostname"]/value)[1]', 'nvarchar(max)') as action_client_hostname, event_data.value ('(event/action[@name="database_name"]/value)[1]', 'nvarchar(max)') as action_database_name, event_data.value ('(event/action[@name="nt_username"]/value)[1]', 'nvarchar(max)') as action_nt_username, event_data.value ('(event/action[@name="session_id"]/value)[1]', 'int') as action_session_id, event_data.value ('(event/action[@name="sql_text"]/value)[1]', 'nvarchar(max)') as action_sql_text from xevents go if exists (select * from sys.server_event_sessions where name = 'sqlws_xevents_attention') drop event session sqlws_xevents_attention on server go create event session sqlws_xevents_attention on server add event sqlserver.attention (action (sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.nt_username, sqlserver.session_id, sqlserver.sql_text) where duration > 5000 ) add target package0.ring_buffer with (event_retention_mode = ALLOW_SINGLE_EVENT_LOSS, memory_partition_mode = NONE) go /* alter event session sqlws_xevents_attention on server state = start go --Execute your workload with xevents (event_name) as ( select event.value ('(@name)[1]', 'varchar(max)') as event_name from ((select cast (xest.target_data as xml) as target_data from sys.dm_xe_sessions as xes inner join sys.dm_xe_session_targets as xest on (xes.address = xest.event_session_address) where xes.name = 'sqlws_xevents_attention' and xest.target_name = 'ring_buffer') as td cross apply target_data.nodes ('//event[@name="attention"]') as x (event)) ) select event_name, count(*) from xevents group by event_name go select * from sqlws_xev_attention go alter event session sqlws_xevents_attention on server state = stop go */
調(diào)優(yōu)建議
對(duì)于連接耗時(shí),當(dāng)然務(wù)必要找到具體原因,是網(wǎng)絡(luò)問(wèn)題還是驗(yàn)證問(wèn)題;對(duì)于查詢超時(shí),多為語(yǔ)句性能問(wèn)題導(dǎo)致,如阻塞、未使用合理的索引、輸出數(shù)據(jù)量太大等原因。對(duì)于臨時(shí)解決問(wèn)題,可以在連接配置里、或在程序里的語(yǔ)句級(jí)參數(shù)屬性調(diào)大配置值。當(dāng)然應(yīng)及時(shí)找出問(wèn)題的根源并解決。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。