Saturday, February 16, 2019

get top CPU consuming sessions with sql's

SELECT
       tmp.sid,tmp.serial#,
       program,
       cpu_usage_seconds,
       sqlarea.SQL_fullTEXT,
       DBMS_LOB.substr(sqlarea.SQL_fullTEXT, 32767) SQL
  from (select s.username,program,
               t.sid,
               s.serial#,
               s.sql_id,
               SUM(VALUE / 100) as cpu_usage_seconds
          FROM v$session s, v$sesstat t, v$statname n
         WHERE t.STATISTIC# = n.STATISTIC#
           AND NAME like '%CPU used by this session%'
           AND t.SID = s.SID
           AND s.status = 'ACTIVE'
           AND s.username is not null
         GROUP BY username,program, t.sid, s.serial#, s.sql_id) tmp,
       V$sqlarea sqlarea
 where tmp.sql_id = sqlarea.sql_id
 order by cpu_usage_seconds desc;

No comments:

Post a Comment