|
【赛迪网-it技术报道】在进行数据库调优时,代码的性能瓶颈至关重要,oracle数据库提供的dbms_profiler包可以特别方便的发现瓶颈的所在之处。
dbms_profiler在使用之前可能需要安装,具体安装步骤如下:
◆1:执行$oracle_home/rdbms/admin/profload.sql
◆2:创建一个用于存放跟踪信息的schema
create user profiler identified by profiler default tablespace users quota unlimited on users;
grant connect to profiler;
create public synonym plsql_profiler_runs for profiler.plsql_profiler_runs;
create public synonym plsql_profiler_units for profiler.plsql_profiler_units;
create public synonym plsql_profiler_data for profiler.plsql_profiler_data;
create public synonym plsql_profiler_runnumber for profiler.plsql_profiler_runnumber;
◆3:使用刚刚创建的profiler用户执行如下脚本或代码:
$oracle_home/rdbms/admin/proftab.sql
grant select on plsql_profiler_runnumber to public;
grant select, insert, update, delete on plsql_profiler_data to public;
grant select, insert, update, delete on plsql_profiler_units to public;
grant select, insert, update, delete on plsql_profiler_runs to public;
安装成功后测试:
执行
begin
dbms_profiler.start_profiler('123');
for i in 1 .. 1000 loop
insert into a values (i || '');
end loop;
commit;
dbms_profiler.stop_profiler();
end;
执行后使用下面的代码检查:
select c.line#, c.total_occur, c.total_time, c.min_time, c.max_time
from plsql_profiler_runs a, plsql_profiler_units b, plsql_profiler_data c
where a.run_comment = '123'
and b.unit_owner = ''
and a.runid = b.runid
and a.runid = c.runid
and b.unit_number = c.unit_number
注意:每次dbms_profiler.start_profiler的输入参数需要改变,否则便不能分别运行后的运行结果了。
除此之外b.unit_owner =‘’中的约束值如果是在package里面需要是包名,如果是procedure则是procedure的名字。实在在不知道什么名字时可以在plsql_profiler_units中查一下。
此外,运行结果可以通过plsql developer来观察,需要新建一个test,在profiler中可以查看它的运行结果,示例如下:
|