连接超时对于连接超时,首先可以查看Connectivity Ring Buffer中的LoginTimers类型错误来分析,如果想获得更详尽的信息,再通过抓包工具network monitor。具体方法和语
连接超时
对于连接超时,首先可以查看Connectivity Ring Buffer中的LoginTimers类型错误来分析,如果想获得更详尽的信息,再通过抓包工具network monitor。
具体方法和语句可参考以下文章:
https://blogs.msdn.microsoft.com/apGCdsd/2011/11/20/ring-buffersql-server-2008/
Http://ultrasql.blog.51cto.com/9591438/1583446
查询超时
对于查询超时,针对SQL Server 2012以下的版本,使用Profiler的TSQL_Duration模板的基础上,添加“Errors and Warnings”下的“Attention”,根据捕获到的Attention结合上下文去查找相应的语句;对于SQL Server 2012及以上版本,直接使用扩展事件监控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
调优建议
对于连接耗时,当然务必要找到具体原因,是网络问题还是验证问题;对于查询超时,多为语句性能问题导致,如阻塞、未使用合理的索引、输出数据量太大等原因。对于临时解决问题,可以在连接配置里、或在程序里的语句级参数属性调大配置值。当然应及时找出问题的根源并解决。
--结束END--
本文标题: SQL Server超时诊断
本文链接: https://lsjlt.com/news/37600.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0