使用 DBMS_APPLICATION_INFO 进行实时监控

dbms_application_info 包,用于交换环境中执行处理的时间点信息。
让一个长时间运行的PL/SQL程序提供处理信息。以下代码段每隔1000 行记录就更新应用程序的信息,内容主要是处理的记录数和花费的时间。

conn plsql/plsql
SQL> create table s_employee_test as select * from hr.employees;

Table created
SQL> insert into s_employee_test select * from s_employee_test
2 ;

29 rows inserted
...
...
SQL> insert into s_employee_test select * from s_employee_test;

237568 rows inserted

SQL> commit;

Commit complete
SQL> select count(*) from s_employee_test;

COUNT(*)
----------
475136

SQL> declare
2 cursor cur_emp is
3 select employee_id,salary,rowid from s_employee_test;
4 lv_new_salary_num number;
5 lv_count_num pls_integer := 0;
6 lv_start_time_num pls_integer;
7 begin
8 lv_start_time_num := dbms_utility.get_time;
9 for cur_emp_rec in cur_emp loop
10 lv_count_num := lv_count_num + 1;
11 lv_new_salary_num := cur_emp_rec.salary;
12 update s_employee_test set salary = lv_new_salary_num
13 where rowid=cur_emp_rec.rowid;
14 if mod(lv_count_num,1000) = 0 then
15 dbms_application_info.set_module('records Processed:'||lv_count_num,'Elapsed :'||(dbms_utility.get_time-lv_start_time_num)/100||' sec');
16 end if;
17 end loop;
18 commit;
19 dbms_application_info.set_module('records Processed:'||lv_count_num,'Elapsed :'||(dbms_utility.get_time-lv_start_time_num)/100||' sec');
20 end;
21 /

PL/SQL procedure successfully completed



通过查询 v$session,可以监控处理过程。

select username,sid,serial#,module,action from v$session where username='PLSQL';


SQL> select count(*) from s_employee_test;

COUNT(*)
----------
475136

SQL> select username,sid,serial#,module,action from v$session where username='PLSQL';

USERNAME SID SERIAL# MODULE ACTION
------------------------------ ---------- ---------- ------------------------------------------------ --------------------------------
PLSQL 9 309 PL/SQL Developer SQL Window - select username,sid
PLSQL 132 64 PL/SQL Developer Command Window - New
PLSQL 192 187 records Processed:74000 Elapsed :20.37 sec
PLSQL 197 239 PL/SQL Developer Main session

SQL> select username,sid,serial#,module,action from v$session where username='PLSQL';

USERNAME SID SERIAL# MODULE ACTION
------------------------------ ---------- ---------- ------------------------------------------------ --------------------------------
PLSQL 9 309 PL/SQL Developer SQL Window - select username,sid
PLSQL 132 64 PL/SQL Developer Command Window - New
PLSQL 192 187 records Processed:94000 Elapsed :25.82 sec
PLSQL 197 239 PL/SQL Developer Main session

...
...
SQL> select username,sid,serial#,module,action from v$session where username='PLSQL';

USERNAME SID SERIAL# MODULE ACTION
------------------------------ ---------- ---------- ------------------------------------------------ --------------------------------
PLSQL 9 309 PL/SQL Developer SQL Window - select username,sid
PLSQL 132 64 PL/SQL Developer Command Window - New
PLSQL 192 187 records Processed:475136 Elapsed :130.18 sec
PLSQL 197 239 PL/SQL Developer Main session


最后一次查询的时间是在 PL/SQL 程序单元已经完成时。

以上演示了一种特定环境的有价值的技巧,并[b][color=red]提供了实时监控的机制[/color][/b],这样能更容易地[b]准确测量出程序已经运行的时间[/b][color=red][/color],[b]并可估算出程序还要多长时间才能完成[/b][color=red][/color]。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值