ITPub博客

首页 > 数据库 > Oracle > DDL_LOCK_TIMEOUT

DDL_LOCK_TIMEOUT

原创 Oracle 作者:goolen 时间:2014-05-07 14:21:17 0 删除 编辑

最近又看了一遍11g的一些新特性,其实有的在工作中还是挺有用也很常用的,记录一下

DDL_LOCK_TIMEOUT 


Property Description
Parameter type Integer
Default value 0
Modifiable ALTER SESSION
Range of values 0 to 1,000,000 (in seconds)
Basic No


官方这样解释:

specifies a time limit for how long DDL statements will wait in a DML lock queue. The default value of zero indicates a status of NOWAIT. The maximum value of 1,000,000 seconds will result in the DDL statement waiting forever to acquire a DML lock.

If a lock is not acquired before the timeout period expires, then an error is returned.


在11g之前,如果一个表上有锁,那么其他session在对这个表进行DDL操作(如drop table,create index,drop column等)的时候,是以nowait的方式执行的

也就是说你执行一个DDL,如果其他session上对这个表加了锁,那么你的操作会马上抛错而不等待锁资源的获得

ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired


oracle在11g中提供了 DDL_LOCK_TIMEOUT 这么一个参数,在一定程度上解决了一些实际的问题,因为我们要操作一个DDL的时候,并不清楚这个表是否有DML操作

这个参数默认是为0,单位是秒,表示默认是以nowait方式执行的;

最大值为1000000秒,表示DDL语句永远等待一个DML锁资源

这个参数可以在session级别来设置,下面我们来试验一把

不设置此参数,默认是nowait

session A:

SQL> drop table t1 purge;

Table dropped.

SQL> set timing on
SQL> create table t1 as select * from emp;

Table created.
Elapsed: 00:00:00.02
SQL> update t1 set sal=sal+100 where empno=7788;
1 row updated.
Elapsed: 00:00:00.01

更新后不commit


session B:

SQL> set timing on
SQL> create index ind_1 on t1(empno);
create index ind_1 on t1(empno)
                      *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

Elapsed: 00:00:00.00


我们可以看到,不设置等待时间,DDL操作立马就抛错,终止执行


在看一下设置了等待时间后的效果

session A:

SQL> set time on
10:48:28 SQL> update t1 set sal=sal+100 where empno=7788;

1 row updated.

Elapsed: 00:00:00.00
10:48:32 SQL> 

update后不commit


session B:

SQL> set time on
10:48:40 SQL> alter session set ddl_lock_timeout=10;

Session altered.

Elapsed: 00:00:00.01
10:49:35 SQL> create index ind_1 on t1(empno);
create index ind_1 on t1(empno)
                      *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

Elapsed: 00:00:10.01
10:49:54 SQL> 

我们看到设置了ddl_lock_timeout,DDL操作等待了10秒后才抛出错误

如果此DDL在还没有timeout之前获得了DML锁,那么这个操作就会成功执行。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23249684/viewspace-1155837/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-10-20

  • 博文量
    121
  • 访问量
    731660