denrepo

OracleASH & AWR

What was running between two times (AWR ASH)

For "it was slow at 2 a.m." questions. Prompts for a start and end time (YYYY-MM-DD HH24:MI) and ranks SQL and events from AWR's history, where each sample represents about ten seconds.

Diagnostics PackPrompts for input

Not yet verified. How scripts are tested

ora-ash-window.sql
1CLEAR COLUMNS2SET LINESIZE 140 PAGESIZE 100 TRIMOUT ON TAB OFF VERIFY OFF3COLUMN sql_id      FORMAT A134COLUMN activity    FORMAT A455COLUMN est_db_secs HEADING "EST DB SECS" FORMAT 999,999,9906 7SELECT * FROM (8  SELECT sql_id,9         NVL(event, 'ON CPU') AS activity,10         COUNT(*) * 10 AS est_db_secs11  FROM dba_hist_active_sess_history12  WHERE sample_time BETWEEN TO_TIMESTAMP('&start_time', 'YYYY-MM-DD HH24:MI')13                        AND TO_TIMESTAMP('&end_time', 'YYYY-MM-DD HH24:MI')14  GROUP BY sql_id, NVL(event, 'ON CPU')15  ORDER BY COUNT(*) DESC16) WHERE ROWNUM <= 20;

Save it as ora-ash-window.sql and run it with SQL> @ora-ash-window.

Open in denrepo

More Oracle scripts: ASH & AWR