메뉴 건너뛰기

bysql.net

3. SQL 트레이스

2010.06.06 11:27

balto 조회 수:24433

- 실행계획과 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.16 158078
66 4. Prefetch file balto 2010.07.10 30036
65 5. 오라클 Lock file 휘휘 2010.06.06 27851
64 2. DB 버퍼 캐시 file 휘휘 2010.05.23 25201
» 3. SQL 트레이스 file balto 2010.06.06 24433
62 4. Array Processing 활용 file 휘휘 2010.07.04 24009
61 1. 기본 아키텍처 [1] file 휘휘 2010.05.22 23370
60 2. SQL 처리과정 file 휘휘 2010.06.27 23142
59 5. Undo file 토시리 2010.05.30 21921
58 11. Shared Pool file 실천하자 2010.05.30 21804
57 2. 트랜잭션 수준 읽기 일관성 file 휘휘 2010.06.06 21542
56 1 장. 오라클 아키텍처 운영자 2010.05.19 21220
55 9. Static vs. Dynamic SQL [1] balto 2010.07.03 19837
54 3. 버퍼 Lock [1] 휘휘 2010.05.23 18680
53 5. Fetch Call 최소화 file 휘휘 2010.07.05 18248
52 1. Explain Plan 실천하자 2010.06.06 18005
51 9. ASH(Active Session History) 실천하자 2010.06.13 16941
50 6. 바인드 변수의 부작용과 해법 file 실천하자 2010.06.27 16100
49 8. 블록 클린아웃 휘휘 2010.05.30 15603
48 8. PL/SQL 함수 호출 부하 해소 방안 토시리 2010.07.11 15577