TSQL to detect long running queries against the database

Published 29 August 07 04:37 AM | SQL Master 

When I'm performing a performance analysis on a 24/7 application and dealing with PSS I had been given the following TSQL to identify the long running queries against a database.

 

select r.session_id, s.host_name, s.program_name, s.host_process_id,

r.status, r.wait_time,wait_type,r.wait_resource,

substring(qt.text,(r.statement_start_offset/2) +1,

(case when r.statement_end_offset = -1

then len(convert(nvarchar(max), qt.text)) * 2

else r.statement_end_offset end -r.statement_start_offset)/2)

as stmt_executing,r.blocking_session_id, r.cpu_time,r.total_elapsed_time,r.reads,r.writes,

r.logical_reads, r.plan_handle

from sys.dm_exec_requests r

cross apply sys.dm_exec_sql_text(sql_handle) as qt, sys.dm_exec_sessions s

where r.session_id > 50 and r.session_id=s.session_id

order by r.session_id, s.host_name, s.program_name, r.status

Comments

# Other SQL Server Blogs around the Web said on August 29, 2007 4:51 AM:

When I'm performing a performance analysis on a 24/7 application and dealing with PSS I had been

# SSQA.net - SqlServer-QA.net said on August 29, 2007 4:58 AM:

When I'm performing a performance analysis on a 24/7 application and dealing with PSS I had been

# sql server t sql date said on July 15, 2008 8:13 AM:

PingBack from http://brandy.onlineshoppingvidsworld.info/sqlservertsqldate.html

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.