블로그는 나의 힘!
[ Programing ]/Database2019. 12. 9. 18:46

- DMV(Dynamic Management View) : 동적관리뷰

 

1. 쿼리

SELECT TOP 20
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  [쿼리계획이_컴파일후_실행될때_사용된_총CPU시간(마이크로초)],
     qs.last_worker_time [마지막_실행될때_사용된_CPU시간(마이크로초)],
     qs.total_elapsed_time/1000000 [실행완료하는데 소요된 총 경과시간(마이크로초)_초로변환],
     qs.last_elapsed_time/1000000 [최근 실행완료하는데 소요된 경과시간(마이크로초)_초로변환],
     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.last_worker_time DESC
-- ORDER BY qs.total_logical_reads DESC
-- ORDER BY qs.total_logical_writes DESC
-- ORDER BY qs.total_worker_time DESC

 

 

 

2. 기타

1) "VIEW SERVER STATE" 권한 필요.
2) 쿼리 완료될때 마다 통계 업데이트



3. 참고사이트

http://blog.sqlauthority.com/2010/05/14/sql-server-find-most-expensive-queries-using-dmv/
http://msdn.microsoft.com/ko-kr/library/ms189741.aspx

 

sys. dm_exec_query_stats (Transact-sql) - SQL Server

sys.dm_exec_query_stats(Transact-SQL)sys.dm_exec_query_stats (Transact-SQL) 이 문서의 내용 --> 적용 대상: SQL Server Azure SQL DatabaseAzure Synapse Analytics(SQL DW) 병렬 데이터 웨어하우스 APPLIES TO: SQL Server Azure SQL Database Azure Synapse Analytics (SQL DW) Parallel Da

docs.microsoft.com

출처: https://rocabilly.tistory.com/102

Posted by Mister_Q