【问题标题】:Alternative for 'ddl_lock_timeout' in oracle 10goracle 10g 中“ddl_lock_timeout”的替代方案
【发布时间】:2015-01-30 09:43:54
【问题描述】:

在 oracle 11g 中允许设置会话和系统参数,称为ddl_lock_timeout。当您需要执行一些语句并且资源被高度使用(以避免ORA-00054 exception)时,它非常有用。

但情况是10g中没有这样的参数。

当然,我可以使用这样的结构:

DECLARE START_DATE DATE := SYSDATE;
BEGIN
  LOOP
    IF SYSDATE>START_DATE+30/60/60/24 THEN
      EXIT;
    END IF;
    BEGIN
      <some statement>
      EXIT;
    EXCEPTION WHEN OTHERS THEN
      IF sqlcode != -54 THEN
        RAISE;
      END IF;
    END;
   END LOOP;
END;

并且通过使用它,我会尝试在一个循环中执行该语句 30 秒,但这里的问题是该语句执行了很多次,可能会引起一些麻烦(我不确定,但我感觉不知何故),但使用ddl_lock_timeout,该语句只执行一次,然后等待更蓬松的资源。

有什么想法吗?

【问题讨论】:

  • 你想达到什么目的? Oracle 建议是:“不要将 DDL 用于业务逻辑”。

标签: oracle oracle11g oracle10g


【解决方案1】:

这是对为什么 LOCK TABLE 不一定有效的解释。

LOCK TABLE - trick may not be working in all situations.

Session 1:                              Session 2:

create table table1(a number);
insert into table1 values(1);
commit;
update table1 set a = 2;



                                    lock table table1 in exclusive mode;
                                    <waits...>



commit;
                                        "Table(s) Locked." 

update table1 set a = 3;  <-- notice session 1 goes in queue now. 

                                        DDL fails with "resource busy with NOWAIT".
                                    Reason is DDL first commit the previous transaction 
                                    before executing the DDL.  And when it commits 
                                    session 1 gets the lock as it was already in queue.

【讨论】:

  • 谢谢。你是对的,我的答案不起作用,我会删除它。我想现在最好的答案是“没有好的选择”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-15
相关资源
最近更新 更多