执行PLSQL数据库需要:
1. 以SYS用户执行$ORACLE_HOME/rdbms/admin/profload.sql, 创建dbms_profiler包
2. 当前schema(以scott为例)执行$ORACLE_HOME/rdbms/admin/proftab.sql创建profiler需要的表和sequence. 注意:这些都是普通的表。一般鼓励每个schema创建自己的profiler表,以免混淆。
3. grant execute on dbms_profiler to scott.
使用SQL profiler例子:
begin
dbms_profiler.start_profiler ('Performance');
pls;
--procedure to be profiled.
dbms_profiler.stop_profiler ();
end;
创建sql developer报表找出耗时最长的十行代码:
1. 运行SQL Developer, View --> Reports --> User Defined Reports --> New Reports
2. 填入报表名,在Query里贴入:
select * from (
select to_char(run.run_date, 'yyyy/mm/dd hh24:mi:ss') run_date, substr(run_comment, 1,20) run_comment, unit.unit_name object_name,
dat.line#,substr(src.text, 1, 30) source_code, dat.total_occur, to_char(dat.total_time/1000000000, '9990.999') total_time, to_char(dat.min_time/1000000000, '9990.999') min_time, to_char(dat.max_time/1000000000, '9990.999') max_time
from plsql_profiler_runs run, plsql_profiler_units unit, plsql_profiler_data dat, all_source src
where
dat.line#=src.line and
unit.unit_name=src.name and
unit.unit_owner=src.owner and
run_comment =:run_comment and
run.runid=unit.runid
and unit.runid=dat.runid
and unit.unit_number=dat.unit_number
and unit.unit_name<>''
order by dat.total_time desc)
where rownum <= 10;
3. 点击确定后保存报表。每次运行报表时,需要填入Comment作为绑定变量传入。注意大小写。每次运行plsql profiler,用不同comment以示区别。
在$ORACLE_HOME/rdbms/admin下
profdemo.sql
profsum.sql
profrep.sql
作为参考。可以创建自己的报表。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/638844/viewspace-769683/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/638844/viewspace-769683/