메뉴 건너뛰기

bysql.net

3. SQL 트레이스

2010.06.06 20:27

balto 조회 수:21175

- 실행계획과 autotrace 보다 강력한 튜닝도구

▣ SQL Trace 사용 방법 - 자기세션에서 트레이스

(1) 1단계 - alter 문 사용하여 SQL 문 실행하기

alter session set sql_trace=true;

select * from emp where empno=7900;

alter session set sql_trace=false;

(2) 2단계 - 트레이스 파일찾는 스크립트 실행(trc 파일의 이름이 출력된다)

select r.value || '/' || lower(t.instance_name) || '_ora_'

|| ltrim(to_char(p.spid)) || '.trc' trace_file

from v$process p, v$session s, v$parameter r, v$instance t

where p.addr = s.paddr

and r.name = 'user_dump_dest'

and s.sid = (select sid from v$mystat where rownum = 1) ;

(3) tkprof 사용하여 프로파일 파일 생성하기(DOS 명령어, report.prf를 생성한다.)

tkprof orcl_ora_4000.trc report.prf sys=no;

(실습결과)

fig3-1.jpg


(4) 이벤트 트레이스를 추가하는 방법 - 아래 명령어를 실행한 다음 (1),(2),(3) 과정 반복

alter session set events '10046 trace name context forever, level 8';

 

(실습결과)

fig3-5.jpg


 

▣ SQL Trace 설명

- Elapsed time = cpu time + wait time = reponse 시점 - call 시점

- call count

SELECT 문 = Parse + Execute + Fetch

DML 문 = Parse + Execute

- Fetch call = 레코드 건수 / ArraySize

(실습결과)

fig3-3.jpg


(질의문 실행 흐름)

fig3-4.jpg 


▣ SQL Trace 사용 방법 - 다른세션에서 트레이스

(1) 9i에서

exec dbms_system.set_ev(145, 3, 10046, 12, '');

=> 시리얼 번호가 3인 145번 세션에서 레벨 12로 10046 이벤트 트레이스

(2) 10g

(시작)

begin

dbms_monitor.session_trace_enable(

session_id=>145, serial_num=>3,

waits=>TRUE, binds=>TRUE);

end;

(해제)

begin

dbms_monitor.session_trace_disable(

session_id=>145, serial_num=>3);

end;

(3) oradebug 명령어

oradebug help

oradebug setospid 3796

oradebug unlimit /* 트레이스 파일의 크기를 없앰 */

oradebug event 10046 trace name context forever, level 8

oradebug tracefile_name /* 트레이스 파일 이름 확인 */

oradebug event 10046 trace name context off /* 트레이스 해제 */

oradebug close_trace

▣ SQL Trace 사용 방법 - Service, Modele, Action 단위로 트레이스 걸기- 10g

- show parameter service_name;

- /* 서비스나 모듈 이름 보는 방법 */

select sid, service_name, module, action

from v$session

where service_name <> 'SYS$BACKGROUND';

(1) 세션에 거는 방법 - 세션 이름이 eCRM인 세션에 모두 트레이스 걸기

begin

dbms_monitor.serv_mod_act_trace_enable(

service_name=>'eCRM',

module_name=>dbms_monitor.all_modules,

action_name=>dbms_monitor.all_actions,

waits=>true, binds=>true);

end;

/

(트레이스 설정 확인)

select primary_id service_name, qualifier_id1 module, qualifier_id2 action,

waits, binds

from dba_enabled_traces;

(트레이스 해제)

begin

dbms_monitor.serv_mod_act_trace_disable(

service_name=>'eCRM',

module_name=>dbms_monitor.all_modules,

action_name=>dbms_monitor.all_actions);

end;

/

(2) 모듈에 거는 방법

(모듈 이름 바꾸기)

begin

dbms_application_info.set_module(

module_name=>'emp manager',

action_name=>'select emp');

end;

/

(확인)

select sid, service_name, module, action

from v$session

where service_name <> 'SYS$BACKGROUND';

(모듈에 걸기)

begin

dbms_monitor.serv_mod_act_trace_enable(

service_name=>'eCRM', module_name=>'emp manager',

action_name=>dbms_monitor.all_actions,

waits=>true, binds=>true);

end;

/

(트레이스 설정 확인)

select primary_id service_name, qualifier_id1 module, qualifier_id2 action,

waits, binds

from dba_enabled_traces;

(트레이스 해제)

begin

dbms_monitor.serv_mod_act_trace_disable(

service_name=>'eCRM', module_name=>'emp manager',

action_name=>dbms_monitor.all_actions);

end;

/

(실행 중 부분 모듈에 걸기)

..

dbms_application_info.set_action('update emp');

..

begin

dbms_monitor.serv_mod_act_trace_enable(

service_name=>'eCRM', module_name=>‘emp manager',

action_name=>'update emp',

waits=>true, binds=>true);

end;

/

select primary_id service_name, qualifier_id1 module, qualifier_id2 action,

waits, binds

from dba_enabled_traces;

(특정값으로 설정된 세션에만 트레이스 걸기)

- 설정

exec dbms_session.set_identifier('oraking');

- 트레이스 걸기

begin

dbms_monitor.client_id_trace_enable(

client_id=>'oraking',

waits=>false, binds=>false);

end;

/

번호 제목 글쓴이 날짜 조회 수
7 2. Cursor_Sharing balto 2010.07.17 10213
6 7. Result 캐시 휘휘 2010.07.19 12969
5 8. I/O 효율화 원리 휘휘 2010.07.19 7742
4 부록 휘휘 2010.07.19 7238
3 6. RAC 캐시 퓨전 file 토시리 2010.07.19 12631
2 3. Deterministic 함수 사용 시 주의사항 file 실천하자 2010.07.19 10588
1 진행기록 운영자 2011.08.23 6588