如何分析在线SQL Server数据库压力?

时间:2011-08-10 09:47:05

标签: sql-server sql-server-2008 analysis

我想分析SQL Server的压力。所以我可以找到哪个表比其他表查询更多,并为此缓存数据。 那我怎么能这样做呢?

1 个答案:

答案 0 :(得分:1)

查看本文解释了如何使用DMV(动态管理视图)通过逻辑读取,写入或CPU时间检索前n个最昂贵的SQL查询:

SQL SERVER – Find Most Expensive Queries Using DMV

如果链接不可用,我已经包含以下查询:

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