Oracle SQL Trace 和 10046 事件跟踪(八)

2014-11-24 18:26:01 · 作者: · 浏览: 14
0 3 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 3 0.00 0.00 0 3 0 1
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: SYS (recursive depth: 1)
Rows Row Source Operation
------- ---------------------------------------------------
1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=3 r=0 w=0 time=24 us)
1 INDEX UNIQUE SCAN I_OBJ1 (cr=2 r=0 w=0 time=12 us)(object id 33)
********************************************************************************


在report.txt文件头有各个数据的解释,根据以下一些指标可以分析一下SQL的执行性能:  
(query+current)/rows 平均每行所需的block数,太大的话(超过20)SQL语句效率太低
Parse count/Execute count parse count应尽量接近1,如果太高的话,SQL会进行不必要的reparse。要检查Pro*C程序的MAXOPENCURSORS是不是太低了,或不适当的使用的RELEASE_CURSOR选项  
rows Fetch/Fetch Fetch Array的大小,太小的话就没有充分利用批量Fetch的功能,增加了数据在客户端和
SQL> EXEC DBMS_SUPPORT.start_trace(waits=>TRUE, binds=>FALSE);
SQL> EXEC DBMS_SUPPORT.stop_trace;
在Oracle10g里推荐使用DBMS_MONITOR:
SQL> EXEC DBMS_MONITOR.session_trace_enable;
SQL> EXEC DBMS_MONITOR.session_trace_enable(waits=>TRUE, binds=>FALSE);
SQL> EXEC DBMS_MONITOR.session_trace_disable;
3.对其他用户session跟踪
首先从v$session中获得sid和serial#, 然后:
SQL> EXEC DBMS_SYSTEM.set_sql_trace_in_session(sid=>123, serial#=>1234, sql_trace=>TRUE);
SQL> EXEC DBMS_SYSTEM.set_sql_trace_in_session(sid=>123, serial#=>1234, sql_trace=>FALSE);

SQL> EXEC DBMS_SYSTEM.set_ev(si=>123, se=>1234, ev=>10046, le=>8, nm=>' ');
SQL> EXEC DBMS_SYSTEM.set_ev(si=>123, se=>1234, ev=>10046, le=>0, nm=>' ');

SQL> @ /rdbms/admin/dbmssupp.sql --DBMS_SUPPORT包需要单独安装,用sys用户安装
SQL> EXEC DBMS_SUPPORT.start_trace(sid=>123, serial=>1234, waits=>TRUE, binds=>FALSE);
SQL> EXEC DBMS_SUPPORT.stop_trace(sid=>123, serial=>1234);
也可以通过使用oradebug工具来设置10046事件, 首先通过V$PROCESS获得该session的spid, 然后:
SQL> oradebug setospid 12345;
SQL> oradebug unlimit;
SQL> oradebug event 10046 trace name context forever, level 8;
SQL> oradebug event 10046 trace name context off;
在Oracle10g里推荐使用DBMS_MONITOR:
SQL> EXEC DBMS_MONITOR.session_trace_enable(session_id=>1234, serial_num=>1234);
SQL> EXEC DBMS_MONITOR.session_trace_enable(session_id =>1234, serial_num=>1234, waits=>TRUE, binds=>FALSE);
SQL> EXEC DBMS_MONITOR.session_trace_disable(session_id=>1234, serial_num=>1234);
以下还能同时跟踪多个session, client_id通过 DBMS_SESSION 包设置在 v$session 里:
SQL> exec dbms_session.set_identifier('tim_hall');
SQL> select sid,serial#,username,client_identifier from v$session where client_identifier is not null;
SQL> EXEC DBMS_MONITOR.client_id_trace_enable(client_id=>'tim_hall');
SQL> EXEC DBMS_MONITOR.client_id_trace_enable(client_id=>'tim_hall', waits=>TRUE, binds=>FALSE);
SQL> EXEC DBMS_MONITOR.client_id_trace_disable(client_id=>'tim_hall');
以下还能同时跟踪多个session, service_name, module, action columns通过 DBMS_APPLICATION_INFO 包设置在 v$session 里:
SQL> EXEC DBMS_MONITOR.serv_mod_act_trace_enable(service_name=>'wending.lk', module_name=>'test_api', action_name=>'running');
SQL> EXEC DBMS_MONITOR.serv_mod_act_trace_enable(service_name=>'wending.lk', module_name=>'test_api', action_name=>'running', waits=>TRUE, binds=>FALSE);
SQL> EXEC DBMS_MONITOR.serv_mod_act_trace_disable(service_name=>'wending.lk', modu