본문으로 바로가기

[MS-SQL] 현재 실행중인 쿼리 보기

category Dev/MS-SQL 2016. 9. 7. 15:55

현재 실행중인 쿼리 보기

SELECT      dm_ws.wait_duration_ms 실행대기시간, 
            dm_ws.wait_type 대기형태,  
            dm_es.status 실행상태,  
            dm_t.TEXT 실행쿼리,  
            dm_qp.query_plan 실행계획,  
            dm_ws.session_ID 세션아이디, 
            dm_es.cpu_time , 
            dm_es.memory_usage , 
            dm_es.logical_reads 논리적읽기, 
            dm_es.total_elapsed_time 총실행시간, 
            dm_es.program_name , 
            DB_NAME(dm_r.database_id) DB명,  
            --Optional columns 
            dm_ws.blocking_session_id blk,  
            dm_r.wait_resource, 
            dm_es.login_name, 
            dm_r.command, 
            dm_r.last_wait_type  
FROM        sys.dm_os_waiting_tasks dm_ws  
INNER JOIN   sys.dm_exec_requests dm_r   
ON          dm_ws.session_id = dm_r.session_id 
INNER JOIN   sys.dm_exec_sessions dm_es   
ON          dm_es.session_id = dm_r.session_id 
CROSS APPLY sys.dm_exec_sql_text ( dm_r.sql_handle ) dm_t  
CROSS APPLY sys.dm_exec_query_plan ( dm_r.plan_handle ) dm_qp  
WHERE       dm_es.is_user_process = 1  AND DB_NAME(dm_r.database_id) = 'DB명'

댓글을 달아 주세요