转自:http://blog.itpub.net/35489/viewspace-764856/
1. sql 详细执行计划,主要检查驱动路径,索引是否合适;同一个pl/sql窗口连续执行即可;
explain plan for (select * from HW_PC_SIGNED_COMPANY_V sc) ;
select * from table(dbms_xplan.display(null,null,'all'));
2. sql monitor,查看sql主要花在哪些时间,真实的行数和IO;三个sql依次执行;
SELECT /*+monitor*/ * from HW_PC_SIGNED_COMPANY_V sc ;
select * from v$sql s where s.SQL_TEXT like 'SELECT /*+monitor*/ * from HW_PC_SIGNED%' ;
select dbms_sqltune.report_sql_monitor('ftswqgup6hzxx') from dual ;
3. SQLT
http://space.itpub.net/35489/viewspace-764348
查看TXT文件。
4. SQL Profile 及使用SQL Tuning Advisor来尝试SQL调优
http://space.itpub.net/35489/viewspace-747164
5. 10046 EVENT
trace 文件的格式都是 sid_ora_pid.trc , 其中sid 表示数据库的instance name, pid 表示 process id .
A. 可以在PL/SQL中加入如下的语句来进行trace .
EXECUTE IMMEDIATE 'ALTER SESSION SET timed_statistics=true' ;
EXECUTE IMMEDIATE 'ALTER SESSION SET max_dump_file_size=“unlimited”';
EXECUTE IMMEDIATE 'ALTER SESSION SET TRACEFILE_IDENTIFIER=''TEST_TRACEFILE''';
EXECUTE IMMEDIATE 'ALTER SESSION SET EVENTS ''10046 trace name context forever,level 8''';
在最后加入如下语句执行
EXECUTE IMMEDIATE 'ALTER SESSION SET EVENTS ''10046 trace name context off'';
B. 使用10046 event 跟踪其他用户session :
对其他用户session设置 dbms_system.set_ev
说明:5个参数 sid/serial#/ev/level/username
Select sid,serial# from v$session where username is not null ;
SID SERIAL#
---------- ---------- -----
113 227
或者通过spid查询sid, serial# :
SQL> select b.*, a.* from v$process a, v$session b
where a.addr = b.paddr and a.spid in (1914, 19140) ;
执行跟踪:
exec dbms_system.set_ev(113,227,10046,8,'');
结束跟踪:
exec dbms_system.set_ev(113,227,10046,0,'');
最后的trace文件都需要使用 tkprof 进行格式转化
tkprof xxx.trc xxx.txt explain=apps/passwd sort='(prsela,exeela,fchela)'
6. SQL Trace
SQL> set autotrace traceonly
显示: expain+statistics(不显示数据)