메뉴 건너뛰기

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;

/

번호 제목 글쓴이 날짜 조회 수
67 Front Page file 운영자 2010.05.17 154864
66 1 장. 오라클 아키텍처 운영자 2010.05.20 17841
65 1. 기본 아키텍처 [1] file 휘휘 2010.05.23 19898
64 3. 버퍼 Lock [1] 휘휘 2010.05.24 15225
63 2. DB 버퍼 캐시 file 휘휘 2010.05.24 21916
62 4. Redo file 휘휘 2010.05.24 11314
61 9. Snapshot too old balto 2010.05.30 8100
60 10. 대기 이벤트 balto 2010.05.30 8010
59 7. Consistent vs. Current 모드 읽기 휘휘 2010.05.31 10536
58 8. 블록 클린아웃 휘휘 2010.05.31 12280
57 11. Shared Pool file 실천하자 2010.05.31 18511
56 5. Undo file 토시리 2010.05.31 18648
55 1. 트랜잭션 동시성 제어 실천하자 2010.05.31 8631
54 6. 문장수준 읽기 일관성 file 토시리 2010.06.01 10432
53 2장. 트랜잭션과 Lock 운영자 2010.06.01 6895
52 1. Explain Plan 실천하자 2010.06.06 14663
51 2. AutoTrace 실천하자 2010.06.06 8597
50 3장. 오라클 성능 관리 운영자 2010.06.06 6694
» 3. SQL 트레이스 file balto 2010.06.06 21175
48 4. DBMS_XPLAN 패키지 balto 2010.06.06 10461