Advertisement
james_yuuu

資料庫監控

May 12th, 2019
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --1.找出最耗費資料庫CPU前10 名的語法:
  2. SELECT TOP 10
  3. substring(ST.text, ( QS.statement_start_offset / 2 ) + 1,
  4. ( ( CASE statement_end_offset WHEN -1 THEN DATALENGTH (st.text) ELSE QS.statement_end_offset END - QS.statement_start_offset ) / 2 ) + 1 ) AS statement_text ,
  5. total_worker_time / 1000 AS total_worker_time_ms,
  6. execution_count,
  7. ( total_worker_time / 1000 ) / execution_count AS avg_worker_time_ms,
  8. total_logical_reads,
  9. total_logical_reads / execution_count AS avg_logical_reads,
  10. qp.query_plan
  11. FROM sys.dm_exec_query_stats qs
  12. CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle ) st
  13. CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
  14. ORDER BY total_worker_time DESC
  15.  
  16. --2.找出查詢時間最久的前50名sql語法:
  17. SELECT TOP 50 [text],*, (total_worker_time / execution_count) AS avgworkertime
  18. FROM sys.dm_exec_query_stats
  19. CROSS APPLY sys.dm_exec_sql_text(sql_handle)
  20. ORDER BY avgworkertime DESC
  21.  
  22. --3.找出最常使用的sql語法
  23. SELECT TOP 50 [text],*
  24. FROM sys.dm_exec_query_stats qs
  25. CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
  26. ORDER BY qs.plan_generation_num DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement