Identifying SQL Server Performance Problems

前端 未结 7 921
自闭症患者
自闭症患者 2021-02-04 14:58

We\'re having sporadic, random query timeouts on our SQL Server 2005 cluster. I own a few apps that use it, so I\'m helping out in the investigation. When watching the % CPU tim

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 15:43

    This will give you the top 50 statements by average CPU time, check here for other scripts: http://www.microsoft.com/technet/scriptcenter/scripts/sql/sql2005/default.mspx?mfr=true

    SELECT TOP 50
            qs.total_worker_time/qs.execution_count as [Avg CPU Time],
            SUBSTRING(qt.text,qs.statement_start_offset/2, 
                (case when qs.statement_end_offset = -1 
                then len(convert(nvarchar(max), qt.text)) * 2 
                else qs.statement_end_offset end -qs.statement_start_offset)/2) 
            as query_text,
            qt.dbid, dbname=db_name(qt.dbid),
            qt.objectid 
    FROM sys.dm_exec_query_stats qs
    cross apply sys.dm_exec_sql_text(qs.sql_handle) as qt
    ORDER BY 
            [Avg CPU Time] DESC
    

提交回复
热议问题