線上重定義過程中需要exclusive lock.

來源:互聯網
上載者:User

執行DBMS_REDEFINITION.FINISH_REDEF_TABLE 預存程序完成表的線上重定

義。在此procedure運行過程中,原表會被以Exclusive lock mode(TM lmode=6)排他模式鎖住

極為短暫的一段時間(秒級),具體這段時間的長短受到原表上資料量的影響。但有時候應用繁忙時可能不能立刻獲得!

那麼能不能使用一個參數讓它多等待一段時間呢?

下面做個實驗看看:

Microsoft Windows [版本 6.1.7601]
著作權 (c) 2009 Microsoft Corporation。著作權所有,並保留一切權利。

C:\Users\ibsadmin>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期四 8月 16 17:49:47 2012

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

串連到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter ddl_lock_timeout

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
ddl_lock_timeout                     integer     0
SQL> select A.sid, b.serial#,
  2    decode(A.type,
  3        'MR', 'Media Recovery',
  4        'RT','Redo Thread',
  5        'UN','User Name',
  6        'TX', 'Transaction',
  7        'TM', 'DML',
  8        'UL', 'PL/SQL User Lock',
  9        'DX', 'Distributed Xaction',
 10       'CF', 'Control File',
 11       'IS', 'Instance State',
 12       'FS', 'File Set',
 13       'IR', 'Instance Recovery',
 14       'ST', 'Disk Space Transaction',
 15       'TS', 'Temp Segment',
 16       'IV', 'Library Cache Invalida-tion',
 17       'LS', 'Log Start or Switch',
 18       'RW', 'Row Wait',
 19       'SQ', 'Sequence Number',
 20       'TE', 'Extend Table',
 21       'TT', 'Temp Table',
 22       'Unknown') LockType,
 23   c.object_name,
 24   b.username,
 25   b.osuser,
 26   decode(a.lmode,   0, 'None',
 27               1, 'Null',
 28               2, 'Row-S',
 29               3, 'Row-X',
 30               4, 'Share',
 31               5, 'S/Row-X',
 32               6, 'Exclusive', 'Unknown') LockMode,
 33   B.MACHINE,D.SPID
 34   from v$lock a,v$session b,all_objects c,V$PROCESS D
 35   where a.sid=b.sid and a.type in ('TM','TX')
 36   and c.object_id=a.id1
 37   AND B.PADDR=D.ADDR;

未選定行

在另一個SESSION:

Microsoft Windows [版本 6.1.7601]
著作權 (c) 2009 Microsoft Corporation。著作權所有,並保留一切權利。

C:\Users\ibsadmin>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期四 8月 16 17:52:55 2012

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

串連到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table t (cloa int);

表已建立。

SQL> insert into t values(1);

已建立 1 行。

 

SQL>

回到原來的session:
SQL> set timing on
SQL> truncate table t;
truncate table t
               *
第 1 行出現錯誤:
ORA-00054: 資源正忙, 但指定以 NOWAIT 方式擷取資源, 或者逾時失效

經過時間:  00: 00: 00.10
SQL>  select A.sid, b.serial#,
  2     decode(A.type,
  3         'MR', 'Media Recovery',
  4         'RT','Redo Thread',
  5         'UN','User Name',
  6         'TX', 'Transaction',
  7         'TM', 'DML',
  8         'UL', 'PL/SQL User Lock',
  9         'DX', 'Distributed Xaction',
 10        'CF', 'Control File',
 11        'IS', 'Instance State',
 12        'FS', 'File Set',
 13        'IR', 'Instance Recovery',
 14        'ST', 'Disk Space Transaction',
 15        'TS', 'Temp Segment',
 16        'IV', 'Library Cache Invalida-tion',
 17        'LS', 'Log Start or Switch',
 18        'RW', 'Row Wait',
 19        'SQ', 'Sequence Number',
 20        'TE', 'Extend Table',
 21        'TT', 'Temp Table',
 22        'Unknown') LockType,
 23    c.object_name,
 24    b.username,
 25    b.osuser,
 26    decode(a.lmode,   0, 'None',
 27                1, 'Null',
 28                2, 'Row-S',
 29                3, 'Row-X',
 30                4, 'Share',
 31                5, 'S/Row-X',
 32                6, 'Exclusive', 'Unknown') LockMode,
 33    B.MACHINE,D.SPID
 34    from v$lock a,v$session b,all_objects c,V$PROCESS D
 35    where a.sid=b.sid and a.type in ('TM','TX')
 36    and c.object_id=a.id1
 37    AND B.PADDR=D.ADDR;

       SID    SERIAL# LOCKTYPE                    OBJECT_NAME
---------- ---------- --------------------------- ------------------------------

USERNAME                       OSUSER                         LOCKMODE
------------------------------ ------------------------------ ---------
MACHINE
----------------------------------------------------------------
SPID
------------------------
        31       1615 DML                         T
SYS                            115-DTHVM\ibsadmin             Row-X
WORKGROUP\115-DTHVM
3748

經過時間:  00: 00: 00.18
SQL> alter session set ddl_lock_timeout = 5;

會話已更改。

經過時間:  00: 00: 00.01
SQL> truncate table t;
truncate table t
               *
第 1 行出現錯誤:
ORA-00054: 資源正忙, 但指定以 NOWAIT 方式擷取資源, 或者逾時失效

經過時間:  00: 00: 05.01

另一個SESSION提交資料:

回到原來 session執行:
SQL> truncate table t;

表被截斷。

經過時間:  00: 00: 03.14
SQL>

雖然不能保證每次都成功,但完全可以增加成功的機率!

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.