Oracle

게시글 보기
작성자 유건데이타 등록일 2015-07-15
제목 SESSION IDLE TIME MONITORING
SESSION IDLE TIME MONITORING
============================


클라이언트와 서버 간에 커뮤니케이션은 없지만, 커넥션이 맺어진 상태의
세션을 inactive 혹은 idle 상태라고 할 수 있다. idle session은 resource를
계속 hold 하고 있어 성능 저하의 원인이 되기도 한다. 때문에 idle session을
감시하고, 이를 최소화 하는 것은 DBA의 중요한 역할 중에 하나이다.

<7.2 version>
어떤 세션이 idle 상태인지, 아닌지에 관한 정보를 Data Dictionary를 통해
한번에 얻어낼 수 있는 방법은 없다. 다음은 idle session에 관한 정보를 얻어
내는 방법이다.

idle time을 감시하기 위해서는 다음과 같은 단계를 수행해야 한다.

(1) 에 있는 RESOURCE_LIMIT 파라미터를 TRUE로 설정해야 한다.

(2) 변경된 파라미터가 적용될 수 있도록 데이타베이스를 shutdown /startup을
한다.

(3) user_profile를 생성하여, the idle_time parameter를 특정 값으로
설정한다.

$sqlplus system/manager
sql> grant create profile to scott;

sql> connect scott/tiger
sql> create profile user_profile limit idle_time 5; (5분)

sql> connect system/manager
sql> alter user scott profile user_profile;


(4) default profile에 위의 내용을 설정하거나, 관리하고자 하는 user들의
profile로 설정한다. user마다 profile을 가지고 있을 수 있다는 점을
주의해야 한다.


< 관련 Data Dictionary Views >

- V$SESSTAT
- V$TIMER
- V$STATNAME

< SCRIPT >

SYS로 sqlplus를 connect 한 후 다음 script를 실행한다.


/************** IDLE_TIME MONITOR SCRIPT ******************/

column sid format 999
column last format a22 heading "Last non-idle time"
column curr format a22 heading "Current time"
column secs format 99999999.999 heading "idle-time |(seconds)"
column mins format 999999.99999 heading "idle-time |(minutes)"

select sid, to_char((sysdate - (hsecs - value)/(100*60*60*24)),
'dd-mon-yy hh:mi:ss') last,
to_char(sysdate, 'dd-mon-yy hh:mi:ss') curr,
(hsecs - value)/(100) secs, (hsecs - value)/(100*60) mins
from v$timer, v$sesstat
where statistic# = (select statistic# from v$statname
where name = 'process last non-idle time');


< 수행결과 >

SQL> @idle
idle-time idle-time
SID Last non-idle time Current time (seconds) (minutes)
---------------------------------------------------
1 01-jul-94 12:21:52 06-nov-94 03:38:10 11070977.580 184516.29300
2 01-jul-94 12:21:52 06-nov-94 03:38:10 11070977.620 184516.29367
3 01-jul-94 12:21:52 06-nov-94 03:38:10 11070977.650 184516.29417
4 01-jul-94 12:21:52 06-nov-94 03:38:10 11070977.680 184516.29467
5 01-jul-94 12:21:52 06-nov-94 03:38:10 11070977.710 184516.29517
6 06-nov-94 03:38:07 06-nov-94 03:38:10 3.000 .05000
7 06-nov-94 01:06:27 06-nov-94 03:38:10 9102.970 151.71617
9 06-nov-94 03:36:56 06-nov-94 03:38:10 73.620 1.22700
10 06-nov-94 03:37:49 06-nov-94 03:38:10 20.910 .34850

9 rows selected.

몇 분 후 다시 실행하면

SQL> @idle
idle-time idle-time
SID Last non-idle time Current time (seconds) (minutes)
---------------------------------------------------
1 01-jul-94 12:21:53 06-nov-94 03:40:15 11071101.930 184518.36550
2 01-jul-94 12:21:53 06-nov-94 03:40:15 11071101.970 184518.36617
3 01-jul-94 12:21:53 06-nov-94 03:40:15 11071102.000 184518.36667
4 01-jul-94 12:21:53 06-nov-94 03:40:15 11071102.020 184518.36700
5 01-jul-94 12:21:53 06-nov-94 03:40:15 11071102.050 184518.36750
6 06-nov-94 03:40:12 06-nov-94 03:40:15 3.400 .05667
7 06-nov-94 01:06:28 06-nov-94 03:40:15 9227.320 153.78867
9 06-nov-94 03:36:57 06-nov-94 03:40:15 197.970 3.29950
10 06-nov-94 03:37:50 06-nov-94 03:40:15 145.260 2.42100

9 rows selected.


몇 분 후 다시 실행하면

SQL> @idle
idle-time idle-time
SID Last non-idle time Current time (seconds) (minutes)
----------------------------------------------------
1 01-jul-94 12:21:53 06-nov-94 03:40:51 11071138.170 184518.96950
2 01-jul-94 12:21:53 06-nov-94 03:40:51 11071138.210 184518.97017
3 01-jul-94 12:21:53 06-nov-94 03:40:51 11071138.240 184518.97067
4 01-jul-94 12:21:53 06-nov-94 03:40:51 11071138.270 184518.97117
5 01-jul-94 12:21:53 06-nov-94 03:40:51 11071138.300 184518.97167
6 06-nov-94 03:40:11 06-nov-94 03:40:51 39.650 .66083
7 06-nov-94 01:06:27 06-nov-94 03:40:51 9263.570 154.39283
9 06-nov-94 03:36:57 06-nov-94 03:40:51 234.220 3.90367
10 06-nov-94 03:37:49 06-nov-94 03:40:51 181.510 3.02517

9 rows selected.

RESOURCE_LIMIT 파라미터를 true로 설정하면, user 세션이 비활성화 되자 마자
오라클은 V$TIMER에 기록을 남긴다. 이 기록은 나중에 정확히 idle한 시간을 알
수 있도록 해준다.
마지막 쿼리 결과 중 SID = 7인 세션을 살펴보면, 마지막 non-idle time은
(즉, 비활성되기 시작한 지점) 06-nov-94 01:06:27이고, 현재 시간은
06-nov-94 03:40:51로 나타나 있고, 이 둘의 차이가 결국 IDLE TIME인
9263.570초가 된다. V$TIMER는 DB가 생성될때, 0에서 시작하기 때문에 1부터
5까지의 세션은 DB가 생성된 이후 계속 IDLE 상태에 있음을 알 수 있다.
위 script를 실행하면, IDLE TIME LIMIT이 지난 세션도 IDLE 상태로
보여진다. 사용자가 트랜젝션을 다시 시작하려 할 때, 세션이 끝나게 되고,
다시 쿼리를 실행해보면 해당 세션은 나오지 않게 된다.

[참고] 특정 session 만 kill 하는 방법

만약, sid 가 10 인 session 을 kill 하려면,

select sid, serial#, username, program
from v$session
where sid=10;

에서 serial#(예를 들어 6) 과 session 에 대한 정보를 한번 확인한 다음,

alter system kill session '10, 6';

하면 된다.


<7.3 이상에서>
7.3 이상에서는 간단하게 v$session에서 idel time에 관한 정보를
파악할 수 있다. (초 단위)

select sid, username, last_call_et idle_time from v$session;

SID USERNAME LAST_CALL_
---------- ------------------------------ ----------
1 453
2 453
3 453
4 453
5 453
6 SYS 0
8 SCOTT 73

출처 : OTN

오라클 유지보수 유건데이타
Comment
등록된 코멘트가 없습니다.