What SQL and sessions are running?

GUIs like TOAD and Enterprise Manager can show this better, but they’re not always to hand. Every session active now or within the last minute is shown.

set pages 9999 lines 132
col username form a20
col osuser form a20
col program form a50
col minutes form 999
alter session set nls_date_format = 'Dy DD-Mon-YYYY HH24:MI:SS'
/
select distinct
s.sid, s.username, s.osuser, s.program||' '||s.module program,
s.status, s.last_call_Et/60 minutes, s.logon_time, w.state, w.event, w.seconds_in_wait ,
q.sql_text
from v$session s, v$sql q, v$session_wait w
where ( s.status = 'ACTIVE' or last_call_et < 60 )
and s.sql_hash_value = q.hash_value
and s.sql_address = q.address
and s.sid = w.sid
order by s.sid
/
set pages 9999 lines 80 head on feed 6

3 Responses to “What SQL and sessions are running?”

  1. Mukesh Says:

    Following are errors on 10.2.0.1.0 on WIN XP SP2-

    [code]

    SQL> set pages 9999 lines 132
    SQL> col username form a20
    SQL> col osuser form a20
    SQL> col program form a50
    SQL> col minutes form 999
    SQL> alter session set nls_date_format = `Dy DD-Mon-YYYY HH24:MI:SS’
    2 /
    alter session set nls_date_format = `Dy DD-Mon-YYYY HH24:MI:SS’
    *
    ERROR at line 1:
    ORA-00911: invalid character

    [/code]

    [code]

    SQL> select distinct
    2 s.sid, s.username, s.osuser, s.program||’ `||s.module program,
    3 s.status, s.last_call_Et/60 minutes, s.logon_time, w.state, w.event, w.seconds_in_wait ,
    4 q.sql_text
    5 from v$session s, v$sql q, v$session_wait w
    6 where ( s.status = `ACTIVE’ or last_call_et < 60 )
    7 and s.sql_hash_value = q.hash_value
    8 and s.sql_address = q.address
    9 and s.sid = w.sid
    10 order by s.sid
    11 /
    where ( s.status = `ACTIVE’ or last_call_et < 60 )
    *
    ERROR at line 6:
    ORA-00923: FROM keyword not found where expected

    [/code]

  2. Andrew Fraser Says:

    Sorry Mukesh - was due to wordpress editor turning ‘ into ` symbol. Should be fixed now in main post.

  3. Mukesh Says:

    Its working fine now. Thanks.

Leave a Reply