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

发布时间:2020-08-13 08:13:10 作者:不一样的天空w
来源:ITPUB博客 阅读:224

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)

推荐阅读:
  1. MySQL 存储过程CASE语句用法
  2. sqlserver查找包含某个语句的所有存储过程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

dbms 过程 package

上一篇:SQL性能第2篇:查询分析和访问路径制定

下一篇:安卓用线程实现随机抽奖

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》