CPU Sessions usage

we can use view to get each session cpu usage.

RAC / Cloud RDS: Top 10 sessions from last 1 hour cpu usage

select * from (select * from

(

select username,sid,

       round((cpu_usage/(

                        select sum(value) total_cpu_usage

                          from gv$sesstat t

                         inner join gv$session  s on ( t.sid = s.sid )

                         inner join gv$statname n on ( t.statistic# = n.statistic# )

                         where n.name like '%CPU used by this session%'

                           and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24

                        ))*100/16,2) cpu_usage_per_cent,

       module_info,client_info,sql_id

  from

(

select nvl(s.username,'Oracle Internal Proc.') username,s.sid,s.sql_id,t.value cpu_usage, nvl(s.module, s.program) module_info, decode(s.osuser,'oracle', s.client_info, s.osuser) client_info

  from gv$sesstat t

       inner join gv$session  s on ( t.sid = s.sid )

       inner join gv$statname n on ( t.statistic# = n.statistic# )

where n.name like '%CPU used by this session%'

   and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24

) s1

)

order by cpu_usage_per_cent desc) where rownum < 10;

NON-RAC / Cloud RDS: Top 10 sessions from last 1 hour cpu usage

select * from (select * from

(

select username,sid,

       round((cpu_usage/(

                        select sum(value) total_cpu_usage

                          from v$sesstat t

                         inner join v$session  s on ( t.sid = s.sid )

                         inner join v$statname n on ( t.statistic# = n.statistic# )

                         where n.name like '%CPU used by this session%'

                           and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24

                        ))*100/16,2) cpu_usage_per_cent,

       module_info,client_info,sql_id

  from

(

select nvl(s.username,'Oracle Internal Proc.') username,s.sid,s.sql_id,t.value cpu_usage, nvl(s.module, s.program) module_info, decode(s.osuser,'oracle', s.client_info, s.osuser) client_info

  from v$sesstat t

       inner join v$session  s on ( t.sid = s.sid )

       inner join v$statname n on ( t.statistic# = n.statistic# )

where n.name like '%CPU used by this session%'

   and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24

) s1

)

order by cpu_usage_per_cent desc) where rownum < 10;



Comments

Popular Posts

AWR Report Analysis

Goldengate 19c Installation with issue resolution

Oracle 11g Physical Standy Setup

Oracle 12c 2-node RAC setup in VMware Player 15 -- Part01

Oracle to Postgres

Execution_Explain Plan

Active Session History Analysis

General Queries

Fragmentation & Re-organisation

OEM patches & vulnerabilities