標籤:oracle 12.2 online move
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操作
--建立測試表[email protected]>create table t as select * from dba_objects;Table created.Elapsed: 00:00:00.26[email protected]>insert into t select * from t;79608 rows created.Elapsed: 00:00:00.22[email protected]>/159216 rows created.Elapsed: 00:00:00.38[email protected]>/318432 rows created.Elapsed: 00:00:03.63[email protected]>/636864 rows created.Elapsed: 00:00:05.40[email protected]>/1273728 rows created.Elapsed: 00:00:24.57[email protected]>select bytes/1024/1024 from user_segments;BYTES/1024/1024--------------- 392Elapsed: 00:00:00.07[email protected]>commit;Commit complete.Elapsed: 00:00:00.01[email protected]>alter system flush buffer_cache;System altered.Elapsed: 00:00:27.90--不做move操作時delete操作時間[email protected]>delete from t where object_name=‘T‘;32 rows deleted.Elapsed: 00:00:00.13[email protected]>rollback;Rollback complete.--執行move--session 1[email protected]>select userenv(‘sid‘) from dual;USERENV(‘SID‘)-------------- 1150--session 2 [email protected]>select userenv(‘sid‘) from dual;USERENV(‘SID‘)-------------- 15--session 1[email protected]>alter table t move tablespace examples;Table altered.Elapsed: 00:00:02.45--session 2[email protected]>delete from t where object_name=‘T‘;32 rows deleted.Elapsed: 00:00:02.18[email protected]>rollback;Rollback complete.--session 3[email protected]>select /*+ rule */ sid,lmode,request,type,block from v$lock where sid in (1150,15); SIDLMODE REQUEST TY BLOCK---------- ---------- ---------- -- ---------- 1150 6 0 TM 1 1150 4 0 AE 0 1150 6 0 TS 0 1150 6 0 TX 0 1150 2 0 XR 015 4 0 AE 015 0 3 TM 07 rows selected
從上面的查詢中可以看出表move操作阻塞了delete操作。
2、下面來看12.2版本的線上move操作,需要添加online關鍵字。
--建立測試表[email protected]>select segment_name,bytes/1024/1024 from user_segments;SEGMENT_NAME BYTES/1024/1024------------------------------ ---------------T 392--在沒有move時delete操作時間[email protected]>delete from t where object_name=‘USER_TABLES‘;256 rows deleted.Elapsed: 00:00:00.44[email protected]>rollback;Rollback complete.--session 1[email protected]>select userenv(‘sid‘) from dual;USERENV(‘SID‘)-------------- 23--session 2[email protected]>select userenv(‘sid‘) from dual;USERENV(‘SID‘)-------------- 27--執行move操作--session 1[email protected]>alter table t move online tablespace examples;Table altered.Elapsed: 00:00:34.73--session 2[email protected]>delete from t where object_name=‘USER_TABLES‘;256 rows deleted.Elapsed: 00:00:00.97[email protected]>rollback;Rollback complete.--session 3[email protected]>select /*+ rule */ sid,lmode,request,type,block from v$lock where sid in (23,27); SIDLMODE REQUEST TY BLOCK---------- ---------- ---------- -- ----------27 3 0 TM 027 4 0 AE 027 6 0 TX 023 4 0 AE 023 6 0 OD 023 3 0 DL 023 3 0 DL 023 6 0 TS 023 6 0 TM 023 4 0 TM 023 6 0 TM 023 3 0 TM 023 6 0 TX 023 6 0 TX 023 3 0 TM 023 3 0 TM 016 rows selected.
從上面的操作可以看出12.2的move操作沒有阻塞delete操作。
參考:http://docs.oracle.com/database/122/NEWFT/new-features.htm#GUID-BEEEA34D-3D81-4360-887C-A92BC711816D
本文出自 “DBA Fighting!” 部落格,請務必保留此出處http://hbxztc.blog.51cto.com/1587495/1946289
Oracle 12.2新特性----線上move表