您的位置:首页 > 数据库

PL/SQL性能优化工具profiler的部署和使用

2010-08-10 10:53 761 查看
摘要... 2
PL/SQL性能优化工具profiler的部署和使用... 2
产品名称,产品版本... 2
适用平台... 2
创建及维护日期... 2
引言... 2
执行环境:... 2
访问权限:... 3
用法... 3
简介... 3
描述... 3
先决条件... 3
附录1 调用范例... 4
测试过程创建... 4
调用过程脚本... 5
结果分析... 5
profiler.sql - PL/SQL Profiler (MetaLink Note:243755.1) 5
Profiled Run 3 (plsql_profiler_runs) 5
Profiled PL/SQL Libraries (plsql_profiler_units) 5
Top 10 profiled source lines in terms of Total Time (plsql_profiler_data) 5
Unit:2 DRP.SP_PROCESS_GATHER_JAX1 (all_source) 6


摘要

PL/SQL性能优化工具profiler的部署和使用

当用户等待时间与SQL进程消耗的时间有较大差距,并且这个过程中有PL/SQL脚本的参与,这时,PL/SQL的事件探查器profiler将能在很大程度上给你提供帮助。她能帮助DBA识别出那些耗时较长的sql语句。
比如,一个使用PL/SQL对象(包,过程,函数,触发器)的事务执行了超过1个小时,但10046和tkprof的跟踪分析结果只检测出10分钟的sql执行时间。这种情况下通过使用pl/sql事件探查器profiler,将能提供一个逐行解析的pl/sql程序脚本报告,给出每行程序的具体执行时间信息。
实际的PL/SQL事件探查器是随着RDBMS核心代码一起提供的,这些都可以通过oracle提供的PL/SQL包的类型参考手册上查询得到。事件探查器的包名称为DBMS_PROFILER。
本文主要介绍PL/SQL profiler在8i或者更高版本上的安装及用法。主要是为了提供对plsql程序对象的性能调试。本文主要适用于oracle的8i或者更高版本,但她的使用并不仅仅只限于oracle。
本文描述的主要数据库脚本(profiler.sql)将提供一个由dbms_profiler包提取的完整的性能报告。

产品名称,产品版本

本文涉及的profiler.sql和profgsrc.sql只能使用在oracle 8i及更高的oracle数据库实例上,包括oracle 10g和oracle11g。

适用平台

与平台无关。

创建及维护日期

创建时间:2003-07-14
创建人:carlos Sierra
最后修改时间:2008-04-29

引言

执行环境:

SQL * PLUS

访问权限:

需要SQL* PLUS用户和密码,如果使用的是oracle应用数据库,那么使用APPS连接,否则使用主程序用户和密码。

用法

$ sqlplus APPS/<pwd>
SQL > @profiler.sql <run_id>
这里的run_id是第一次安装dbms_profile包时的返回值。
如果不知道run_id,那么执行无参数的@profiler,脚本将会返回一个run_id列表。

简介

要安装DBMS_PROFILER和生成PL/SQL事件探查器数据,请先阅读下面一节的先决条件。
一旦为某个pl/sql程序对象执行了dbms_profiler.start_profiler和dbms_profiler.stop_profiler,之后就可以执行profler.sql脚本产生一个HTML类型的完整报告,报告中将会标示跟踪期间耗时较长的sql脚本。她也会表明脚本执行的次数。详细可以参考prof.zip中的示例。
DBA可以使用profiler.sql生成的HTML来调试执行期间最为耗时的plsql脚本。

描述

先决条件

1,如果是第一次使用,则需要先行判断dbms_profiler是否已经安装了。
$ sqlplus APPS/<pwd>
SQL> DESC DBMS_PROFILER;
如果DBMS_PROFILER没有安装,使用sys用户连接数据库服务器,并执行下面的脚本来创建对应的程序包。
$ sqlplus sys/<pwd> as sysdba
SQL> @$ORACLE_HOME/rdbms/admin/profload.sql
2,如果是第一次使用,在安装完dbms_profiler之后,使用应用程序用户登录sql plus,运行$ORACLE_HOME/rdbms/admin目录下的proftab.sql脚本,创建相关的数据表如plsql_profiler_runs,plsql_profiler_units,plsql_profiler_data。
$ sqlplus apps/<pwd>
SQL> @proftab.sql
3,由于本文档描述的主要脚本profiler.sql的产生依靠dbms_profiler的支持,所以在运行下面的脚本对数据库对象执行跟踪前腰确认已经安装了对应的程序包。
下面脚本的主要功能是开启和关闭事件探查功能,可以放置到任何plsql脚本块之中。
Begin
Dbms_profiler.start_profiler(‘any comment to identify this execution’);

Dbms_profiler.stop_profiler;

Exception

End;
4,为了要修改plsql库的脚本,dba首先要找到他的定义脚本,备份他,然后执行修改将dbms_profiler的start和stop调用加入其中。
如果无法找到package,procedure,function和trigger等对象的调用,可以使用profgsrc.sql获得定义的脚本,过程调用时需要传入plsql库的对象名称。
$ sqlplus apps/<pwd>
SQL> start profgsrc.sql <PL/SQL library name>;
上面的脚本将访问user_source并获得对象的定义脚本,生成的脚本存放到一个sql类型文件中。
5,一旦将包含start和stop过程的脚本重新编译后,可以执行它来完成对脚本的跟踪。每次执行将会产生一个新的run_id,这个run_id就是后面生成报告的profiler.sql的参数。

附录1 调用范例

测试过程创建

create or replace procedure sp_process_gather_jax1
is
temp_str varchar2(100);
begin
select count(*)
into temp_str
from gather_header gh;
select max(table_name)
into temp_str
from dba_tables dt;
exception
when others then
null;
end sp_process_gather_jax1;

调用过程脚本

declare
a_str varchar2(20);
begin
dbms_profiler.start_profiler('this is the first execution of dbms_profiler.');
-- Call the procedure
sp_process_gather_jax1;
dbms_profiler.stop_profiler;
dbms_output.put_line(a_str);
end;

结果分析

profiler.sql - PL/SQL Profiler (MetaLink Note:243755.1)

Profiled Run 3 (plsql_profiler_runs)

Run
Date
Total Time1
Comment
3
10-AUG-10 10:40:17
17.05
this is the first execution of dbms_profiler.
Note 1: Total Time is in seconds

Profiled PL/SQL Libraries (plsql_profiler_units)

Unit
Owner
Name
Type
Timestamp
Total Time1
Text Header
2
DRP
SP_PROCESS_GATHER_JAX1
PROCEDURE
10-AUG-10 10:40:09
17.04
Note 1: Total Time is in seconds

Top 10 profiled source lines in terms of Total Time (plsql_profiler_data)

Top
Total Time1
Times Executed
Min Time2
Max Time2
Unit
Owner
Name
Type
Line
Text
1
16.66
1
16.66
16.66
2
DRP
SP_PROCESS_GATHER_JAX1
PROCEDURE
13
select count(*)
2
0.38
1
0.38
0.38
2
DRP
SP_PROCESS_GATHER_JAX1
PROCEDURE
17
select max(table_name)
Note 1: Total Time is in seconds
Note 2: Min and Max Time for one execution of this line (in seconds)

Unit:2 DRP.SP_PROCESS_GATHER_JAX1 (all_source)

Line
Total Time1
Times Executed
Text
1
procedure sp_process_gather_jax1
2
is
3
temp_str varchar2(100);
4
begin
5
/*
6
create by jaxzhang 2010.08.06
7
1, 跟踪性能:10046 & prof
8
2,逻辑审核:人
9
*/
10
-- add by jaxzhang 20100810 事件探查器的
11
-- dbms_profiler.start_profiler;
12
13T1
16.66
1
select count(*)
14
into temp_str
15
from gather_header gh;
16
17T2
0.38
1
select max(table_name)
18
into temp_str
19
from dba_tables dt;
20
21
-- add by jaxzhang 20100810 关闭事件探查
22
-- dbms_profiler.stop_profiler;
23
24
-- rollback;
25
26
exception
27
when others then
28
null;
29
0.00
1
end sp_process_gather_jax1;
Note 1: Total Time is in seconds
Note Tn: Top "n" Line in terms of Total Time
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: