Long running queries


Job details

Name: Long running queries
Platform: Oracle
Category: Performance
Description: Checks for long running queries.
Long description: This job checks for long running queries by by merging information from the following performance views: v$sqltext, v$session and v$process.
Version: 3.5
Default schedule: 5,15,25,35,45,55 * * *
Requires engine install: Yes
Compatibility tag: .[type=‘instance’ & databasetype=‘oracle’]/.[hasengine=‘YES’ & eleven_and_above=‘1′]

Parameters

Name Default value Description
Warning time in seconds 600 Active time (in seconds) that will trigger a warning.
Delete statistics older than (hours) 336 For how long (in hours) the statistics will be kept in history table.
Alarm time in seconds 1800 Active time (in seconds) that will trigger an alarm.
Exclude schemas SYS Schema names (comma separated) excluded from being checked for long running queries.

Job Summary

SELECT s.sid, s.machine, s.schemaname, s.logon_time, sysdate - (s.last_call_et / (60 * 60 * 24)) AS ActivityStarted, s.last_call_et AS ActiveSeconds, (SELECT listagg(sql_text) WITHIN GROUP (ORDER BY piece) FROM v$sqltext t WHERE t.address = s.sql_address AND t.hash_value = s.sql_hash_value AND t.piece BETWEEN 0 AND 61) AS SQLQUERY FROM sys.v_$session s, sys.v_$process p WHERE s.status = 'ACTIVE' AND s.type = 'USER' AND s.sql_hash_value > 0 AND p.background IS NULL AND p.addr (+) = s.paddr ORDER BY 2,3,1;

Implementation Details

CREATE TABLE dbw_long_running_history_#instance~id# (histr_date DATE, status VARCHAR2(10), sid NUMBER, machine VARCHAR2(100), schema VARCHAR2(40), logon_time DATE, activity_started DATE, active_sec NUMBER, sql VARCHAR2(2000));

Dependencies and Execution

Reports and Alerting

HISTR_DATE STATUS SID MACHINE SCHEMA LOGON_TIME ACTIVITY_STARTED ACTIVE_SEC SQL

** The report facilitates effective auditing and analysis of long-running queries, providing insights into Query durations, times, and other relevant details.

Upgrade and Version Handling

This comprehensive setup ensures the DBA team can proactively manage database performance and handle any issues related to long query execution times efficiently.