最近发现SQLserver进程占用CPU的很大,导致应用程序部分程序打开缓慢,
把sqlserver服务重新启动以后,情况好转,但是过一段时间或者一会,cpu占用有大了。
最后排除发现是网络内某个机器访问sql过大造成的,怎么找到这个具体的机器呢
利用下面语句:
USE master
GO
----如果要指定数据库就把注释去掉
SELECT * FROM sys.sysprocesses WHERE spid>50 AND DB_NAME([dbid])='JHLZB'
SELECT COUNT(*) FROM sys.dm_exec_sessions WHERE session_id>50
看一下当前的数据库用户连接有多少,都是什么机器连接的,哪个机器连接消耗cpu大,找到具体的机器处理。
然后使用下面语句看一下各项指标是否正常,是否有阻塞,这个语句选取了前10个最耗CPU时间的会话
SELECT TOP 10
[session_id],
[request_id],
[start_time] AS '开始时间',
[status] AS '状态',
[command] AS '命令',
dest.[text] AS 'sql语句',
DB_NAME([database_id]) AS '数据库名',
[blocking_session_id] AS '正在阻塞其他会话的会话ID',
[wait_type] AS '等待资源类型',
[wait_time] AS '等待时间',
[wait_resource] AS '等待的资源',
[reads] AS '物理读次数',
[writes] AS '写次数',
[logical_reads] AS '逻辑读次数',
[row_count] AS '返回结果行数'
FROM sys.[dm_exec_requests] AS der
CROSS APPLY
sys.[dm_exec_sql_text](der.[sql_handle]) AS dest
WHERE [session_id]>50 AND DB_NAME(der.[database_id])='JHLZB'
ORDER BY [cpu_time] DESC