Oracle12.2版本之前,对表做move操作时会对表加exclusive锁,表上无法执行DML操作。虽然move操作有ONLINE子句,但只适用于IOT表,不适用于堆表。这就意味着在对表做move操作时,无法执行任何DML操作,如果对关键表做move操作时只能停业务来完成。到了Oracle12.2版本,推出了一个新特性----在线move表,对于普通堆表可以在move过程中执行DML操作。
下面以11.2.0.4和12.2.0.1这两个版本为对比,观察这一新特性。
1、11.2.0.4版本的move操作
--创建测试表 zx@ORA11G>createtabletasselect*fromdba_objects; Tablecreated. Elapsed:00:00:00.26 zx@ORA11G>insertintotselect*fromt; 79608rowscreated. Elapsed:00:00:00.22 zx@ORA11G>/ 159216rowscreated. Elapsed:00:00:00.38 zx@ORA11G>/ 318432rowscreated. Elapsed:00:00:03.63 zx@ORA11G>/ 636864rowscreated. Elapsed:00:00:05.40 zx@ORA11G>/ 1273728rowscreated. Elapsed:00:00:24.57 zx@ORA11G>selectbytes/1024/1024fromuser_segments; BYTES/1024/1024 --------------- 392 Elapsed:00:00:00.07 zx@ORA11G>commit; Commitcomplete. Elapsed:00:00:00.01 zx@ORA11G>altersystemflushbuffer_cache; Systemaltered. Elapsed:00:00:27.90 --不做move操作时delete操作时间 zx@ORA11G>deletefromtwhereobject_name='T'; 32rowsdeleted. Elapsed:00:00:00.13 zx@ORA11G>rollback; Rollbackcomplete. --执行move --session1 zx@ORA11G>selectuserenv('sid')fromdual; USERENV('SID') -------------- 1150 --session2 zx@ORA11G>selectuserenv('sid')fromdual; USERENV('SID') -------------- 15 --session1 zx@ORA11G>altertabletmovetablespaceexamples; Tablealtered. Elapsed:00:00:02.45 --session2 zx@ORA11G>deletefromtwhereobject_name='T'; 32rowsdeleted. Elapsed:00:00:02.18 zx@ORA11G>rollback; Rollbackcomplete. --session3 sys@ORA11G>select/*+rule*/sid,lmode,request,type,blockfromv$lockwheresidin(1150,15); SID LMODE REQUESTTY BLOCK ------------------------------------------ 1150 6 0TM 1 1150 4 0AE 0 1150 6 0TS 0 1150 6 0TX 0 1150 2 0XR 0 15 4 0AE 0 15 0 3TM 0 7rowsselected
从上面的查询中可以看出表move操作阻塞了delete操作。
2、下面来看12.2版本的在线move操作,需要添加online关键字。
--创建测试表 zx@ORA12C>selectsegment_name,bytes/1024/1024fromuser_segments; SEGMENT_NAME BYTES/1024/1024 --------------------------------------------- T 392 --在没有move时delete操作时间 zx@ORA12C>deletefromtwhereobject_name='USER_TABLES'; 256rowsdeleted. Elapsed:00:00:00.44 zx@ORA12C>rollback; Rollbackcomplete. --session1 zx@ORA12C>selectuserenv('sid')fromdual; USERENV('SID') -------------- 23 --session2 zx@ORA12C>selectuserenv('sid')fromdual; USERENV('SID') -------------- 27 --执行move操作 --session1 zx@ORA12C>altertabletmoveonlinetablespaceexamples; Tablealtered. Elapsed:00:00:34.73 --session2 zx@ORA12C>deletefromtwhereobject_name='USER_TABLES'; 256rowsdeleted. Elapsed:00:00:00.97 zx@ORA12C>rollback; Rollbackcomplete. --session3 sys@ORA12C>select/*+rule*/sid,blockfromv$lockwheresidin(23,27); SID LMODE REQUESTTY BLOCK ------------------------------------------ 27 3 0TM 0 27 4 0AE 0 27 6 0TX 0 23 4 0AE 0 23 6 0OD 0 23 3 0DL 0 23 3 0DL 0 23 6 0TS 0 23 6 0TM 0 23 4 0TM 0 23 6 0TM 0 23 3 0TM 0 23 6 0TX 0 23 6 0TX 0 23 3 0TM 0 23 3 0TM 0 16rowsselected.
从上面的操作可以看出12.2的move操作没有阻塞delete操作。
参考:http://docs.oracle.com/database/122/NEWFT/new-features.htm#GUID-BEEEA34D-3D81-4360-887C-A92BC711816D
原文链接:https://www.f2er.com/oracle/208522.html