0. 사전 테이블 작업
CREATE TABLE before_stat AS SELECT * FROM v$sysstat WHERE 1 = 2 ; CREATE TABLE after_stat AS SELECT * FROM v$sysstat WHERE 1 = 2 ; CREATE TABLE before_event AS SELECT * FROM v$system_event WHERE 1 = 2 ; CREATE TABLE after_event AS SELECT * FROM v$system_event WHERE 1 = 2 ; |
1. Package 생성
Package Header |
CREATE OR REPLACE PACKAGE CHECK_MFO AS TYPE return_stat IS RECORD ( NAME VARCHAR2(64) , CLASS NUMBER , DELTA_VALUE NUMBER , VALUE_PER_SEC NUMBER ) ;
TYPE return_event IS RECORD ( EVENT VARCHAR2(64) , DELTA_TOTAL_WAITS NUMBER , TOTAL_WAITS_PER_SEC NUMBER , DELTA_TIME_WAITED NUMBER , TIME_WAITED_PER_SEC NUMBER ) ;
TYPE return_table_stat IS TABLE OF return_stat ; TYPE return_table_event IS TABLE OF return_event ;
FUNCTION F_CHECK_STAT( i_interval number) RETURN return_table_stat PIPELINED; FUNCTION F_CHECK_EVENT( i_interval number) RETURN return_table_event PIPELINED;
END CHECK_MFO ; / |
Package Body |
CREATE OR REPLACE PACKAGE BODY CHECK_MFO AS
FUNCTION F_CHECK_STAT( i_interval number) RETURN return_table_stat PIPELINED IS pragma autonomous_transaction;
rec return_stat;
-- common V_NAME VARCHAR2(64) ; V_CLASS NUMBER ; V_DELTA_VALUE NUMBER ; V_VALUE_PER_SEC NUMBER ;
BEGIN
EXECUTE IMMEDIATE ' TRUNCATE TABLE before_stat '; EXECUTE IMMEDIATE ' TRUNCATE TABLE after_stat' ;
INSERT INTO before_stat SELECT * FROM v$sysstat ; DBMS_LOCK.SLEEP ( i_interval ) ; INSERT INTO after_stat SELECT * FROM v$sysstat ;
COMMIT ;
FOR v_value IN ( SELECT af.name , af.class , (af.value - be.value) as delta_value , (af.value - be.value) / i_interval as value_per_sec FROM after_stat af , before_stat be WHERE af.name = be.name AND (af.value - be.value) > 0 ) LOOP
V_NAME := v_value.NAME ; V_CLASS := v_value.CLASS ; V_DELTA_VALUE := v_value.delta_value ; V_VALUE_PER_SEC := v_value.value_per_sec ;
REC.NAME := V_NAME ; REC.CLASS := V_CLASS ; REC.DELTA_VALUE := V_DELTA_VALUE ; REC.VALUE_PER_SEC := V_VALUE_PER_SEC ;
PIPE ROW (rec);
END LOOP ;
RETURN;
END F_CHECK_STAT ;
FUNCTION F_CHECK_EVENT ( i_interval number) RETURN return_table_event PIPELINED IS pragma autonomous_transaction; rec return_event;
-- common V_EVENT VARCHAR2(64) ; V_DELTA_TOTAL_WAITS NUMBER ; V_TOTAL_WAITS_PER_SEC NUMBER ; V_DELTA_TIME_WAITED NUMBER ; V_TIME_WAITED_PER_SEC NUMBER ;
BEGIN
EXECUTE IMMEDIATE ' TRUNCATE TABLE before_event' ; EXECUTE IMMEDIATE ' TRUNCATE TABLE after_event' ;
INSERT INTO before_event SELECT * FROM v$system_event WHERE wait_class <> 'Idle' ; DBMS_LOCK.SLEEP ( i_interval ) ; INSERT INTO after_event SELECT * FROM v$system_event WHERE wait_class <> 'Idle' ;
COMMIT ;
FOR v_value IN ( SELECT af.event , (af.total_waits - be.total_waits) as delta_total_waits , (af.total_waits - be.total_waits) / i_interval as total_waits_per_sec , (af.time_waited - be.time_waited) as delta_time_waited , (af.time_waited - be.time_waited) / i_interval as time_waited_per_sec FROM after_event af , before_event be WHERE af.event = be.event AND af.total_waits - be.total_waits > 0 ) LOOP
V_EVENT := v_value.EVENT ; V_DELTA_TOTAL_WAITS := v_value.delta_total_waits ; V_TOTAL_WAITS_PER_SEC := v_value.total_waits_per_sec ; V_DELTA_TIME_WAITED := v_value.delta_time_waited ; V_TIME_WAITED_PER_SEC := v_value.time_waited_per_sec ;
REC.EVENT := V_EVENT ; REC.DELTA_TOTAL_WAITS := V_DELTA_TOTAL_WAITS ; REC.TOTAL_WAITS_PER_SEC := V_TOTAL_WAITS_PER_SEC ; REC.DELTA_TIME_WAITED := V_DELTA_TIME_WAITED ; REC.TIME_WAITED_PER_SEC := V_TIME_WAITED_PER_SEC ;
PIPE ROW (rec);
END LOOP ;
RETURN;
END F_CHECK_EVENT ;
END; /
|
2. 사용방법
SYS@ora11g 21-JUL-16> SELECT * FROM table ( check_mfo.f_check_event(2)) ;
EVENT DELTA_TOTAL_WAITS TOTAL_WAITS_PER_SEC DELTA_TIME_WAITED TIME_WAITED_PER_SEC
------------------------------ ----------------- ------------------- ----------------- -------------------
control file parallel write 1 .5 34 17
log file parallel write 98 49 75 37.5
log file sync 109 54.5 172 86
db file sequential read 2261 1130.5 2 1
db file scattered read 481 240.5 1 .5
db file parallel read 53 26.5 0 0
direct path read 352 176 7 3.5
latch: In memory undo latch 1 .5 0 0
SQL*Net message to client 245 122.5 0 0
9 rows selected.
SYS@ora11g 21-JUL-16> SELECT * FROM table ( check_mfo.f_check_stat(3)) ;
NAME CLASS DELTA_VALUE VALUE_PER_SEC
------------------------------------------------ ---------- ----------- -------------
Requests to/from client 1 611 203.666667
opened cursors cumulative 1 3033 1011
user commits 1 270 90
user calls 1 932 310.666667
recursive calls 1 3478 1159.33333
recursive cpu usage 1 19 6.33333333
session logical reads 1 523193 174397.667
CPU used when call started 128 282 94
CPU used by this session 1 307 102.333333
DB time 1 1020 340
user I/O wait time 1 31 10.3333333
non-idle wait time 1 1022 340.666667
non-idle wait count 1 6219 2073
in call idle wait time 1 7880 2626.66667
중략...
sorts (memory) 64 31 10.3333333
sorts (rows) 64 368269 122756.333
134 rows selected.