Oracle 10g中的SQL跟踪新方法
1. 先确定需要跟踪的Session或者Client
select * from v$session
--会话级别
可以设置identifier方便查询跟踪文件
alter session set TRACEFILE_IDENTIFIER = 'something_here';
begin
--当前自己的Session可以用:
--EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(NULL,NULL, TRUE, TRUE);
--别人的Session可以用:
--dbms_monitor.session_trace_disable(session_id=>97,serial_num=>17);
dbms_monitor.session_trace_enable(session_id=>97,serial_num=>17,waits=>TRUE,binds=>FALSE);
end;
查看启动的会话级别跟踪
select sql_trace,sql_trace_waits,sql_trace_binds from v$session where osuser='FASTENAL\txu'
select sql_trace,sql_trace_waits,sql_trace_binds from v$session
--客户端级别
begin
--dbms_monitor.client_id_trace_enable(client_id=>'LPT-SHAI08',waits=>TRUE,binds=>FALSE);
dbms_monitor.client_id_trace_disable(client_id=>'LPT-SHAI08');
end;
查看启动的客户级别跟踪
select * from dba_enabled_traces
2.确定跟踪文件的位置
--trace文件位置
select value from v$parameter where name='diagnostic_dest'
-- trace文件位置in 11g
select value from v$diag_info where name='Default Trace File'
3.使用tvd$xtat 生成报告。
The tool
http://antognini.ch/top/downloadable-files/
http://antognini.ch/downloads/tvdxtat_40beta9.zip
How to use tvdxtat to generate formatted trace file as html
Command line:
tvdxtat.cmd -i D:\ORACLE11XE\APP\ORACLE\diag\rdbms\xe\xe\trace\xe_ora_328.trc -o d:\mytvd.html -s no -w yes
下面是个收集直方图,删除直方图的例子
-自动收集和手动收集
begin
dbms_stats.gather_table_stats(ownname => 'SYS', tabname =>
'TAB1', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt => 'FOR ALL COLUMNS SIZE AUTO');
end;
analyze table TAB1 compute statistics for columns B size 3
select histogram,num_buckets,column_name from user_tab_col_statistics
where table_name='TAB1' and column_name='B'
begin
dbms_stats.delete_column_stats(ownname => user,
tabname => 'TAB1',
colname => 'B',
col_stat_type => 'HISTOGRAM');
end;
where table_name='TAB1' and column_name='B'