I have application that is up more than 3 days. I can see in logs that there was a moment when application executed some SQL query and this took a lot of time, probably because of some db locks.
I heard that there is a query for such situations. So I need to be able to ask all queries that took, for example, more than 30 minutes. Is it possible?
You can view any SQL statement that executes for more than 6 absolute seconds (the "long running" threshold) using the v$session_longops view. where rownum <=1; This query for long running SQL is especially useful when operations contain long running loops such as shown in the example below.
Right click a database, Reports, Standard Reports, then Object Execution Statistics. It lists the currently cached execution plans, along with the amount of resources and the number of times they've been run.
give this a try:
SELECT TOP 10
total_worker_time/execution_count AS Avg_CPU_Time
,execution_count
,total_elapsed_time/execution_count as AVG_Run_Time
,(SELECT
SUBSTRING(text,statement_start_offset/2,(CASE
WHEN statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(max), text)) * 2
ELSE statement_end_offset
END -statement_start_offset)/2
) FROM sys.dm_exec_sql_text(sql_handle)
) AS query_text
FROM sys.dm_exec_query_stats
ORDER BY AVG_Run_Time DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With