Friday, 15 August 2014

All current sessions detailed information in Database


This query will give the details of all current sessions including Back Ground, and User Sessions, What they are doing, Any blocks happening in database, for what event a session is waiting for along with the command to kill the session. This needs to be executed in sys.



select
p.spid os_process_Id,
'alter system kill session ' || ''''||s.sid||','||s.serial#||''' immediate;' kill_command,
nvl (p.pname,'user process') process_name,
nvl(s.username,'bg') username,
s.sid,
s.serial#,
ss.px_servers_executions,
s.status,
s.osuser,
s.machine,
s.blocking_session,
s.blocking_session_status,
s.state,
s.event,
s.wait_class,
round(s.wait_time_micro/1000000) Wait_time_inSec,
s.service_name,
s.program,
s.module,
s.logon_time,
s.sql_id current_sql_id,
nvl(s.sql_id,prev_sql_id) last_exc_sql_id,
nvl2(blocking_session,s.sid||' Is Blocked by: '||blocking_Session,'No Block') blocking_status,
ss.sql_text,ss.sql_fulltext
from v$session s,v$process p,v$sqlarea ss
where s.paddr=p.addr
and ss.sql_id(+)=s.sql_id
--and s.username like 'SCOTT'
--and s.osuser != 'oracle'
--and s.machine like '%MY_MACHINENAME%'
order by 5;



No comments:

Post a Comment