利用dbms_profile定位存储过程或者package里低效率语句

来源:这里教程网 时间:2026-03-03 15:56:30 作者:

http://blog.chinaunix.net/uid-74941-id-85352.html https://www.bbsmax.com/A/MAzAgQNq59/ 1.检查是否安装了dbms_profiler包 如果没有安装的话,执行下面的语句安装, @?/rdbms/admin/profload.sql 2.把dbms_profiler的执行权限赋于测试用户scott grant execute on dbms_profiler to scott; 3.使用测试用户scott登录,执行proftab.sql(创建跟踪相关系统表)  @?/rdbms/admin/proftab.sql 4.创建一个测试的过程, DMMS_PROFILER的用发: (1).DBMS_PROFILER.start_profiler启动监控 (2).运行所需要分析的存储过程,可以是多个 (3).DBMS_PROFILER.stop_profiler结束监控 --创建测试存储过程 create or replace procedure sp_profiler_test1 as begin    for x in 1..10000    loop        insert into t_t1 values(x);    end loop;    commit; end sp_profiler_test1; / --执行DMMS_PROFILER set serverout on; DECLARE   v_run_number integer; BEGIN   --启动profiler   sys.DBMS_PROFILER.start_profiler(run_number => v_run_number);   --显示当前跟踪的运行序号(后面查询要用)   DBMS_OUTPUT.put_line('run_number:' || v_run_number);   --运行要跟踪的PLSQL   sp_profiler_test1; --前一步创建的测试样例存储过程   --停止profiler   sys.DBMS_PROFILER.stop_profiler; END; / 5.查看结果 --使用测试用户进行查询 select d.line#, --源码行号        s.text, --源码        round(d.total_time/1000000000000,5) total_time , --总运行时间(单位秒)        d.total_occur, --总共运行次数        round(d.min_time/1000000000000,5) min_time, --单次最小运行时间        round(d.max_time/1000000000000,5) max_time --单次最大运行时间           from plsql_profiler_data d, sys.all_source s, plsql_profiler_units u  where d.runid = 2 --运行号    and u.unit_name = 'SP_PROFILER_TEST1' --单元名,即被测试的存储过程名    and u.runid = d.runid    and d.unit_number = u.unit_number    and d.total_occur <> 0    and s.type(+) = u.unit_type    and s.owner(+) = u.unit_owner    and s.name(+) = u.unit_name    and d.line# = nvl(s.line, d.line#)  order by u.unit_number, d.line#; 1秒=1000毫秒bai(ms) 1秒=1,000,000 微秒(μdus) 1秒=1,000,000,000 纳秒(ns) 1秒 =1,000,000,000,000 皮秒(ps) (单位10000亿分之一秒) 1秒=1,000,000,000,000,000飞秒(fs)

相关推荐