处理Resource Busy情况的一段角本

    对于一些建在更新比较频繁的列上的索引, 或者是有大量记录被删除表上的索引, 需要定期进行Rebuild, 对于比较大表上的索引一般会考虑用一定的并行度去建, 以让索引在更短的时间内建好. 但不要忘了将索引的并行度重新设置为1(禁用并行), 否则很容易让所有的SQL都用并行方式来执行, 从而引起主机崩溃. 在很忙的OLTP系统中, 可能常会遇到Resource Busy的错误, 如何确保修改能最后成功呢? 就需要一段角本来处理一下这个错误, 下面是我常用的一段角本:

alter index ...... rebuild ... parallel ... ONLINE;

declare
  resource_busy exception;
  pragma exception_init (resource_busy,-54);
begin
loop
   begin
     execute immediate 'alter index ...... noparallel';
     exit;
   exception
    when resource_busy then
     dbms_lock.sleep(1);
   end;
end loop;
end;
/

    这个角本也可以用在其他的地方, 或者改一下错误号(-54)来处理其他的错误, 怎么用就看你的了!

留言 (10)

非常实用,
我开始喜欢你的blog啦.

我的问题时drop index,老师busy, 删除不掉.
就用Cron job每小时运行一次.

我偏向纯PL/SQL工具.

顺便请教一下, 关于 Instrument logging.

出来 tom 的 debug.f
和 Log4PLSQL,
你有什么推荐?

我已经使用 debug.f 一段时间了, 准备转向 LOG4PLSQL.

你研究得比我Fancy多了, 我都不知道那两个东西是是什么?

是不是要在PL/SQL中向外写Log文件啊?

I'm intreseted in Instrument logging , but now i don't know what it is.

用google搜索一下: LOG4PLSQL debug.f
会分别找到他们的主页.
Tom DebugF
Open source LOG4PLSQL

Tom DebugF: http://asktom.oracle.com/~tkyte/debugf
Open source LOG4PLSQL : http://log4plsql.sourceforge.net/

借用Tom的解释, In every 2nd line of your code, logging what you have done the line before, such as information, debugging, warning, alarm, error...etc.
然后, Developer debuging, QA testing, benchmark, after roll-in production operation trouble-shooting, identifying the performance bottle-neck, just a peace of cake. 味道好极了.

我的认识也是刚刚上了台阶, 从半年前开始 Instrumenting the code (logging, trace every line)

玉面飞龙兄弟也来凑热闹,好极了. Chao 给你红包了吗?

早上在办公室回帖, 被警告要等批准, 搞的无趣, 这下又正常了. ;)

可以我防spam的级别设得太高了, 不要在意.

一笑而过.

太高深了,若是搁我,用这时间游山玩水.

今天用上啦, 哈哈.
SQL optimizer 选择了错误的索引,
只好点到列的次序,重建索引.
明天研究一下 DBMS_STATS.SET_INDEX_STATS,
看看能不能帮助SQL optimizer 选择正确的索引,
好了,该回家吃饭了, 已经是傍晚 7:20pm.
--
declare
resource_busy exception;
pragma exception_init (resource_busy,-54);
begin
loop
begin
execute immediate 'DROP INDEX ABEDBA.ABEPOITEMS_STATUS_UPDDT';
exit;
exception
when resource_busy then
dbms_lock.sleep(0.1);
end;
end loop;
end;
/

发表留言:

« Previous | Main | Next »

英语900句 | English 900

  • We have 50 provinces.
  • 我们有50个省.
  • My country is rich in natural resources.
  • 我国自然资源丰富.
  • That nation is famous for its tourism.
  • 那个国家以旅游业闻名.
  • The biggest festival in my country is the Spring Festival.
  • 我国最大的节日是春节.
  • Geographically, China is located in the Northern Hemisphere.
  • 从地理位置上说, 中国位于北半球.