Home / Database Scripts / How to Find CPU Usage for a Session

How to Find CPU Usage for a Session

How to Find CPU Usage for a Session

SET linesize 145
SET pagesize 9999
COLUMN sid format 9999 heading ‘SID’
COLUMN serial_id format 999999 heading ‘Serial#’
COLUMN session_status format a9 heading ‘Status’ justify right

COLUMN oracle_username format a12 heading ‘Oracle User’ justify right
COLUMN os_username format a9 heading ‘O/S User’ justify right
COLUMN os_pid format 9999999 heading ‘O/S PID’ justify right
COLUMN session_program format a20 heading ‘Session Program’ trunc
COLUMN session_machine format a14 heading ‘Machine’ justify right trunc
COLUMN cpu_value format 999, 999, 999, 999 heading ‘CPU’
prompt +—————————————————-+
prompt | USER sessions ordered BY cpu |
prompt +—————————————————-+
SELECT s.sid                sid,
s.serial#            serial_id,
Lpad(s.status, 9)    session_status,
Lpad(s.username, 12) oracle_username,
Lpad(s.osuser, 9)    os_username,
Lpad(p.spid, 7)      os_pid,
s.program            session_program,
Lpad(s.machine, 14)  session_machine,
sstat.value          cpu_value
FROM   v$process p,
v$session s,
v$sesstat sstat,
v$statname statname
WHERE  p.addr (+) = s.paddr
AND s.sid = sstat.sid
AND statname.statistic# = sstat.statistic#
AND statname.name = ‘CPU used by this session’
ORDER  BY cpu_value DESC



........Subsribe OracleSolutions.pk........
OracleSolutions.pk is exclusively meant to guide the newbies to Learn and Share.

About oracle.solutions

Check Also

How to Get Apps Password From Backend

How to Get Apps Password From Backend   STEP 1.  First login to Database through …

Leave a Reply