denrepo

OraclePerformance

Top sessions by CPU used

Connected sessions ranked by total CPU seconds since they logged on. Good for finding the one batch job or report hammering the box.

Not yet verified. How scripts are tested

ora-top-cpu-sessions.sql
1CLEAR COLUMNS2SET LINESIZE 160 PAGESIZE 100 TRIMOUT ON TAB OFF3COLUMN sid_serial HEADING "SID,SERIAL#" FORMAT A144COLUMN username   FORMAT A155COLUMN program    FORMAT A35 TRUNCATE6COLUMN status     FORMAT A87COLUMN sql_id     FORMAT A138COLUMN cpu_sec    HEADING "CPU SEC" FORMAT 999,999,9909 10SELECT * FROM (11  SELECT s.sid || ',' || s.serial# AS sid_serial,12         s.username, s.program, s.status, s.sql_id,13         ROUND(st.value / 100) AS cpu_sec14  FROM v$sesstat st15  JOIN v$statname n ON n.statistic# = st.statistic#16  JOIN v$session s ON s.sid = st.sid17  WHERE n.name = 'CPU used by this session'18    AND s.type = 'USER'19  ORDER BY st.value DESC20) WHERE ROWNUM <= 15;

Save it as ora-top-cpu-sessions.sql and run it with SQL> @ora-top-cpu-sessions.

Open in denrepo

Part of these runbooks

More Oracle scripts: Performance