線上重定義分割槽表
--建立普通表以及中間分割槽表
CREATE TABLE yz.T (ID NUMBER PRIMARY KEY, TIME DATE);
INSERT INTO yz.T SELECT object_id, CREATED FROM DBA_OBJECTS ;
commit;
CREATE TABLE yz.T_NEW (ID number , TIME date) PARTITION BY RANGE (TIME)
(PARTITION P1 VALUES LESS THAN (TO_DATE('2010-4-20', 'YYYY-MM-DD')),
PARTITION P2 VALUES LESS THAN (TO_DATE('2014-1-10', 'YYYY-MM-DD')),
PARTITION P3 VALUES LESS THAN (TO_DATE('2014-3-28', 'YYYY-MM-DD')),
PARTITION P4 VALUES LESS THAN (MAXVALUE));
1、檢查表是否能夠線上重定義
有主鍵
EXEC DBMS_REDEFINITION.can_redef_table(uname => 'YZ',tname => 'T',options_flag => dbms_redefinition.cons_use_pk);
無主鍵使用rowid
EXEC DBMS_REDEFINITION.can_redef_table(uname => 'YZ',tname => 'T',options_flag => dbms_redefinition.cons_use_rowid);
2、開始線上重定義
exec dbms_redefinition.start_redef_table(uname => 'yz',orig_table => 't',int_table => 't_new');
3、同步資料
EXEC dbms_redefinition.sync_interim_table('YZ','T','T_NEW');
4、在中間表上建立與源表對應的索引、外來鍵、觸發器、統計資訊等
--自動
DECLARE
num_errors PLS_INTEGER;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('yz', 't', 't_new',DBMS_REDEFINITION.CONS_ORIG_PARAMS, TRUE, TRUE, TRUE, TRUE, num_errors);
END;
/
注:中間表上建立索引不是分割槽索引
--手動
alter table t_new add constraint pk_objects_new primary key (id) using index local;
檢視在重定義錯誤
select object_name, base_table_name, ddl_txt from DBA_REDEFINITION_ERRORS;
5、結束重定義
exec dbms_redefinition.finish_redef_table(uname => 'yz',orig_table => 't',int_table => 't_new');
6、重定義過程中有錯誤回滾
exec DBMS_REDEFINITION.ABORT_REDEF_TABLE ('YZ','T','T_NEW');
7、刪除臨時表
truncate table t_new;
drop table t_new purge
8、驗證分割槽
select * from user_tab_partitions;
注:線上重定義分割槽表不能通過goldengate 同步,抽取程序、投遞程序都有t_new相關操作記錄,在複製程序端報錯
OCI Error ORA-01732: data manipulation operation not legal on this view (status = 1732). INSERT /*+ RESTRICT_ALL_REF_CONS */ INTO "YZ"."T_NEW" ("ID","TIME") VALUES (:a0,:a1) Operation failed at seqno 1 rba 31929987 Discarding record on action DISCARD on error 1732 Problem replicating YZ.T_NEW to YZ.T_NEW Mapping problem with insert record (target format)... * ID = 862 TIME = 2013-08-24 11:37:45 *
參考mosGoldenGate Replicat Fails With SQL Error 1732 Mapping on Materialized View (Doc ID 1381948.1)