Describe 세션모니터링 here
set linesize 200 pagesize 999
spool c:\session_monitoring.txt
select sid, username from v$session;
----------------------------------
-- 반드시 아래의 글을 읽어 볼 것!!
----------------------------------
--
-- Oracle 8.1.6에서 테스트 한 것임
-- 해당되는 사용자의 sid를 넣는다. 
-- 프로그램이 강제로 kill하는 중이라면 Serial#는 계속 변화한다.
-- alter system kill session 'sid, serial#'; 명령으로 kill 할 수 있다.
-- define으로 위에서 조회한 것을 토대로&sid에 일률적인 값을 넣는다. 
-- (사용예 : define sid = 12)

-----------------
--세션 모니터링--
-----------------
col NAME FOR a60
SELECT a.sid, b.NAME, a.VALUE 
FROM v$sesstat a, v$statname b
WHERE a.statistic# = b.STATISTIC#
AND VALUE > 10000
AND a.sid = &sid
ORDER BY 1;

--------------------------------
--세션에서 수행되는 SQL문 찾기--
--------------------------------
select a.piece || ' ' || a.sql_text
from v$sqltext_with_newlines a, v$session b
where a.address = b.saddr
and b.sid = &sid
order by 1;

-------------------------
--세션 이벤트 통계 정보--
-------------------------
col event 	format a30
col t_wait	format 999999
col t_out	format 99999
col t_waitd	format 99999
col m_wait	format 99999
select event, 
       total_waits t_wait,
	   total_timeouts t_out,
	   time_waited t_waited, 
	   average_wait a_wait,
	   max_wait m_wait
from v$session_event
where sid = &sid;

------------------
--세션 wait 정보--
------------------
col p1text format a10
col p2text format a10
col p3text format a10
col e_name format a20
col p3 format 999
select
 SID, 
 substr(EVENT, 1, 20) e_name, 
 P1 , 
 P1RAW, 
 P3TEXT, 
 P3 
from v$session_wait
WHERE SID=&sid;

-----------------------
--PGA, UGA양 알아내기--
-----------------------
col username format a20
col program format a20
col pga format a20
col uga format a20
col terminal format a20
select max(decode(t2.num, 1, sid)) sid, 
	   max(decode(t2.num, 1, username)) username, 
	   max(decode(t2.num, 1, pgm)) program, 
	   max(decode(t2.num, 1, terminal, 'UGA, PGA 합계 :')) terminal,
	   sum(pga)||'K' pga,
	   sum(uga)||'K' uga
from (
	  select a.sid, a.username, substr(a.program, 1, 25) as pgm, a.terminal, 
	  max(decode(c.name, 'session pga memory', trunc(value/1000), 0)) pga, 
	  max(decode(c.name, 'session uga memory', trunc(value/1000), 0)) uga 
	  from v$session a, v$sesstat b, v$statname c 
	  where a.sid = b.sid 
	  and b.statistic# = c.statistic# 
	  and c.name like 'session%' 
	  group by a.sid, a.username, substr(a.program, 1, 25), a.terminal) t1,
	  (select 1 as num from dual union all select 2 from dual) t2
group by decode(t2.num, 1, sid);
spool off