本文介绍了有没有办法在 Sql Server 2005 中查看最近的昂贵查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了 SQL Server 2008 中的活动监视器(我知道,对吧?).最近昂贵的查询"选项卡对我帮助很大.

I recently found out about the activity monitor in SQL Server 2008 (I know, duh, right?). The tab "recent expensive queries" helped me quite a lot.

现在我正试图在一个客户端中调试数据库的过度使用,但是那里的服务器是SQL Server 2005.那里有一个活动监视器,但没有最近的昂贵查询"!

Now I'm trying to debug an overuse of the database in one client, but the server there is SQL Server 2005. There is an Activity Monitor there, but not "recent expensive queries" !

只有三个选项卡:进程信息、按进程锁定和按对象锁定.第一个变化很大,我无法跟踪性能问题.

There are just three tabs: Process info, Locks by process and locks by object. The first one changes a lot and I am not being able to track the performance issue.

谢谢!

推荐答案

您可以使用此查看最近的昂贵查询...我一直在使用它,它比活动监视器详细得多.

You can view recent expensive queries with this... I use it all the time, it has far more detail than Activity Monitor.

注意:这仅适用于缓存计划.

NB: This is for cached plans only.

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
--ORDER BY qs.total_logical_reads DESC -- logical reads
--ORDER BY qs.total_logical_writes DESC -- logical writes
ORDER BY qs.total_worker_time DESC -- CPU time

来源

这篇关于有没有办法在 Sql Server 2005 中查看最近的昂贵查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!