SQL追蹤和事件追蹤

yhj20041128001發表於2012-12-31
 追蹤enqueue lock,DDL語句鎖
SQL> alter session set timed_statistics = true;
SQL> alter session set statistics_level=all;
SQL> alter session set max_dump_file_size = unlimited;
SQL> alter session set events '10704 trace name context forever, level 12';
SQL> create table test121(a varchar2(10));
SQL> alter session set events '10704 trace name context off';

比如10046的trace,我們可以跟蹤等待的事件和時間;
以下是10046的生成過程:
SQL> alter session set timed_statistics = true;
SQL> alter session set statistics_level=all;
SQL> alter session set max_dump_file_size = unlimited;
SQL> alter session set events '10046 trace name context forever, level 12';
SQL>
SQL> alter session set events '10046 trace name context off';
使用10053執行SQL計劃的追蹤。
SQL> alter session set events '10053 trace name context forever,level 1'
SQL> explain plan for your_select_query;
SQL> alter session set events '10053 trace name context off';
10049的trace,我們可以看到在語句解析的過程中獲取到的鎖的資訊
以下操作會幫您獲取你想要得到的lock /pin/enq 等資訊:
SQL> alter session set timed_statistics = true;
SQL> alter session set statistics_level=all;
SQL> alter session set max_dump_file_size = unlimited;
SQL> alter session set events '10049 trace name context forever, level 48 ';
SQL> alter table test add name2 varchar2(10); <<<===========DDL
SQL> alter session set events '10049 trace name context off';

SQL_TRACE追蹤session.
SQL> select sid,serial# from v$session where SID=267;
SQL> execute dbms_system.set_sql_trace_in_session(267,996,true);
SQL> execute dbms_system.set_sql_trace_in_session(267,996,false);
使用10046事件追蹤session.
SQL> exec dbms_monitor.session_trace_enable(267,996,waits=>true,binds=>true); 
SQL> exec dbms_monitor.session_trace_disable(267,996);
tkprof/tvdxstat分析SQL
通過dbsm_stats包清除和重新收集表的統計資訊:
SQL> exec dbms_stats.delete_table_stats(user,'TEST1');
SQL> exec dbms_stats.gather_table_stats(user,'TEEST1');
 
檢視錶結構,是否存在有效的索引。
select index_name,table_name,column_name from user_ind_columns
 where table_name=upper('test');
 

使用oradebug跟蹤活動的會話:
oradebug setospid 9077
oradebug event 10046 trace name context forever,level 4
oradebug tracefile_name
oradebug event 10046 trace name context off;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23757700/viewspace-751896/,如需轉載,請註明出處,否則將追究法律責任。

相關文章