2010-06-21 11:12:37| 分类:oracle中的包 |字号 订阅
dbms_application_info提供了通过v$session跟踪脚本运行情况的能力,该包允许我们在v$session设置如下三个列的值,client_info,module,action,还提供了返回这三列的值.dbms_application_info和v$session相关的函数;
dbms_application_info.set_client_info:一般情况下该列填写客户点的信息,但是也可以根据自己的需要填写自己想要的信息
dbms_application_info.set_module:根据自己的需要填写自己想要的信息
dbms_application_info.read_client_info和dbms_application_info.read_module读取这三列的信息
简单例子(1)
declare
l_clinent varchar2(100);
l_mod_name varchar2(100);
l_act_name varchar2(100);
begin
dbms_application_info.set_client_info('my client');
dbms_application_info.read_client_info(l_clinent);
dbms_output.put_line('client='||l_clinent);
dbms_application_info.set_module('my mod','inserting');
dbms_application_info.read_module(l_mod_name,l_act_name);
dbms_output.put_line('mod_name='||l_mod_name);
dbms_output.put_line('act_name='||l_act_name);
end;
client=my client
mod_name=my mod
act_name=inserting
PL/SQL procedure successfully completed
dbms_application_info包监控程序的执行情况
(1)准备测试数据
create table PP_TEST
(
C1 VARCHAR2(50)
)
insert into pp_test select object_name from all_objects;
insert into pp_test select c1 from pp_test;多次执行该语句使数据量足够大,大概30w条
(2)查看当前会话的sid
SQL> select sid from v$mystat where rownum=1;
SID
----------
162
(3) declare
l_new_c1 varchar2(2000);
l_count_num pls_integer:=0;
l_start_time_num pls_integer;
cursor cur_test is select c1,rowid from pp_test;
begin
l_start_time_num:=dbms_utility.get_time;
for cur_test_rec in cur_test loop
l_count_num:=l_count_num+1;
l_new_c1:=cur_test_rec.c1||'_new';
update pp_test
set c1=l_new_c1
where rowid=cur_test_rec.rowid;
if mod(l_count_num,1000)=0 then
dbms_application_info.set_module('更新进程:'||l_count_num,'执行时间:'||(dbms_utility.get_time-l_start_time_num)/100||'sec');
end if;
end loop;
commit;
dbms_application_info.set_module('更新进程:'||l_count_num,'执行时间:'||(dbms_utility.get_time-l_start_time_num)/100||'sec');
end;
(4)以dba的身份登录监控执行情况
SQL> SELECT sid,serial#,client_info,MODULE,action FROM v$session WHERE sid=162;
SID SERIAL#
---------- ----------
CLIENT_INFO
----------------------------------------------------------------
MODULE
------------------------------------------------
ACTION
--------------------------------
162 263
更新进程:43000
执行时间:2.8sec
SQL> SELECT sid,serial#,client_info,MODULE,action FROM v$session WHERE sid=162;
SID SERIAL#
---------- ----------
CLIENT_INFO
----------------------------------------------------------------
MODULE
------------------------------------------------
ACTION
--------------------------------
162 263
更新进程:76000
执行时间:5.49sec
SQL> SELECT sid,serial#,client_info,MODULE,action FROM v$session WHERE sid=162;
SID SERIAL#
---------- ----------
CLIENT_INFO
----------------------------------------------------------------
MODULE
------------------------------------------------
ACTION
--------------------------------
162 263
更新进程:161000
执行时间:11.58sec
注意:在执行上面操作的过程中可能会出现ORA-00257: archiver error. Connect internal only, until freed.解决方法如下
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
FIRST_CHANGE# FIRST_TIME
------------- --------------
1 1 113 10485760 1 NO INACTIVE
2974819 21-6月 -10
2 1 112 10485760 1 NO INACTIVE
2974124 21-6月 -10
3 1 114 10485760 1 NO CURRENT
2978458 21-6月 -10
发现ARC状态为NO,表示系统没法自动做归档。
手工切换日志alter system switch logfile;发现上时间没有反应
alter system set DB_RECOVERY_FILE_DEST_SIZE=6g;
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ---------------
FIRST_CHANGE# FIRST_TIME
------------- --------------
1 1 113 10485760 1 YES INACTIVE
2974819 21-6月 -10
2 1 112 10485760 1 YES INACTIVE
2974124 21-6月 -10
3 1 114 10485760 1 NO CURRENT
2978458 21-6月 -10
再查看时arc变为yes问题
附加:
客户端用sqlplus登陆一个数据库提示
sqlplus [email=test/test@abc]test/test@abc[/email]
ORA-03135: 连接失去联系
进程ID: 11512
会话ID: 408 序列号:6253
sp2-0557 : 禁用产品用户配置文件中的角色时出现错误
error:
ora-03114: 未连接到ORACLE
访问程序包 DBMS_APPLICATION_INFO 时出错
sp2-0575: oracle sql 特征不位于 sql92 entry 层。