如何解決Oracle GoldenGate 沒有主鍵的問題?

lhrbest發表於2017-07-10




本站文章除註明轉載外,均為本站原創: 轉載自

本文連結地址: 

針對沒有主鍵的情況,GoldenGate大概提供了3種方案,大致如下:

1、預設使用所有列當主鍵,透過keycols來實現,這種其實存在一定的問題,在這次的專案中直接否定。
2、透過在源端表中新增ogg_key_id列的方式來實現,這可能會影響應用,因此也直接否定。
3、透過在目標端的表中新增rowid型別的偽列,來實現。透過測試,發現這種相對靠譜,如下是我的測試過程.

我這裡測試的ogg抽取9208 Dataguard standby,同步到10205的例子。另外,我們這裡9i的環境和10g環境均在同一個主機.

1、源端

說明:這裡我模擬的是9i環境超過32列的情況.

—建立測試表

SQL> conn roger/roger
Connected.
SQL> create table t_ALL_TABLES as select * from sys.ALL_TABLES where 1=2;

Table created.

—源端OGG配置

GGSCI (killdb.com) 2> view param ext_std

extract ext_std
 userid ggs@killdb,password ggs
 tranlogoptions archivedlogonly
 tranlogoptions altarchivelogdest /home/ora9/arch_s
 exttrail /home/ora9/ggs/dirdat/ra
 discardfile ./dirrpt/exta.dsc,append, megabytes 500
 fetchoptions USEROWID
 table roger.t_all_tables, tokens (TKN-ROWID = @GETENV ("RECORD", "rowid")) keycols (owner) ;
 table roger.t_buffer;

GGSCI (killdb.com) 3> view param dp1

EXTRACT dp1
RMTHOST 192.168.109.12, MGRPORT 7809 TCPBUFSIZE 5000000
PASSTHRU
RMTTRAIL  ./dirdat/r1
NUMFILES 3000

TABLE roger.*;

GGSCI (killdb.com) 5> dblogin userid ggs@killdb,password ggs
Successfully logged into database.

GGSCI (killdb.com) 6> add trandata roger.t_all_Tables cols(owner) nokey

2014-12-17 01:49:59  WARNING OGG-00869  No unique key is defined for table T_ALL_TABLES. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.

Logging of supplemental redo data enabled for table ROGER.T_ALL_TABLES.

2. 目標端

—建立測試表

 table t_all_tables as select * from sys.all_tables where 1=2;

Table created.

 table t_all_Tables drop column STATUS ;

Table altered.

 table t_all_Tables drop column DROPPED;

Table altered.

 table t_all_tables add (row_id rowid);

Table altered.

 alter table roger.t_all_Tables add constraint t_all_tables_pk unique (row_id) enable;

Table altered.

—目標端OGG配置

GGSCI (killdb.com) 2> view param rep6

replicat rep6
userid  ggs@Roger,password AADAAAAAAAAAAADAKHEJYIFGVAKDPFZBGDFJNEQBBJRISJAAOCHHZEWCEFTCRIRCJDSHUHAJZBFDZEWC,encryptkey kasaur_key
reperror default, discard
discardfile ./dirrpt/rep6.dsc, append, megabytes 50
handlecollisions
assumetargetdefs
----allownoopupdates
numfiles 3000

map roger.t_buffer, target roger.t_buffer;
map roger.t_all_tables , target roger.t_all_tables colmap (usedefaults, row_id = @token ("TKN-ROWID")) keycols (row_id);

3. 啟動程式

–源端

GGSCI (killdb.com) 5> info all

Program     Status      Group       Lag           Time Since Chkpt

MANAGER     RUNNING
EXTRACT     RUNNING     DP1         00:00:00      00:00:07
EXTRACT     RUNNING     EXT_STD     00:00:00      00:00:07

—目標端

GGSCI (killdb.com) 3> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING
JAGENT      STOPPED
EXTRACT     ABENDED     DP1         00:00:00      568:19:49
EXTRACT     ABENDED     EXT1        00:00:00      309:16:06
REPLICAT    STOPPED     REP5        00:00:00      596:25:54
REPLICAT    RUNNING     REP6        00:00:00      00:00:02

 

4. 源端插入測試資料

模擬insert:
–源端

SQL> insert into t_all_Tables select * from sys.all_Tables where rownum < 11;

10 rows created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL>

—-目標端

select count(1) from t_all_Tables;

COUNT(1)
----------
 10
select owner,table_name,row_id from t_all_Tables;

OWNER                          TABLE_NAME                     ROW_ID
------------------------------ ------------------------------ ------------------
SYS                            SEG$                           AAAH3QAABAAAV0yAAA
SYS                            CLU$                           AAAH3QAABAAAV0yAAB
SYS                            OBJ$                           AAAH3QAABAAAV0yAAC
SYS                            FILE$                          AAAH3QAABAAAV0yAAD
SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

10 rows selected.

模式delete

–源端

SQL> delete from t_all_tables where rownum < 5;

4 rows deleted.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> select count(1) from t_all_tables;

COUNT(1)
----------
 6

SQL> select owner,table_name,rowid from t_all_tables;

OWNER                          TABLE_NAME                     ROWID
------------------------------ ------------------------------ ------------------
SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

—目標端:

select count(1) from t_all_Tables;

COUNT(1)
----------
 6

select owner,table_name,row_id from t_all_Tables;

OWNER                          TABLE_NAME                     ROW_ID
------------------------------ ------------------------------ ------------------
SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.


 

模擬update

—源端:

SQL> select owner,table_name,rowid from t_all_tables;

OWNER                          TABLE_NAME                     ROWID
------------------------------ ------------------------------ ------------------
SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

SQL> update t_all_tables set owner='killdb.com' where table_name='COL$';

1 row updated.

SQL> update t_all_tables set owner='killdb.com' where rowid='AAAH3QAABAAAV0yAAF';

1 row updated.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> select owner,table_name,rowid from t_all_tables;

OWNER                          TABLE_NAME                     ROWID
------------------------------ ------------------------------ ------------------
killdb.com                     COL$                           AAAH3QAABAAAV0yAAE
killdb.com                     CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

–目標端:

 select owner,table_name,row_id from t_all_Tables;

OWNER                          TABLE_NAME                     ROW_ID
------------------------------ ------------------------------ ------------------
killdb.com                     COL$                           AAAH3QAABAAAV0yAAE
killdb.com                     CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.


我們可以看到ogg完全是可以支援利用構造rowid偽列的方式來解決沒有主鍵的問題。 然而這種方法
也有一個很大的問題:遷移之後,新環境中的row_id 偽列需要進行drop,這個drop的動作是非常坑爹的。

例如我們客戶這裡的系統,均為2.5TB以上的,最大12TB的庫,那麼drop column就瘋掉了。








About Me

...............................................................................................................................

● 本文轉載自:%E5%A6%82%E4%BD%95%E8%A7%A3%E5%86%B3oracle-goldengate-%E6%B2%A1%E6%9C%89%E4%B8%BB%E9%94%AE%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%9F.html

● 本文在itpub(http://blog.itpub.net/26736162)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● QQ群:230161599     微信群:私聊

● 聯絡我請加QQ好友(646634621),註明新增緣由

● 於 2017-07-01 09:00 ~ 2017-07-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

...............................................................................................................................

拿起手機使用微信客戶端掃描下邊的左邊圖片來關注小麥苗的微信公眾號:xiaomaimiaolhr,掃描右邊的二維碼加入小麥苗的QQ群,學習最實用的資料庫技術。

如何解決Oracle GoldenGate 沒有主鍵的問題?
DBA筆試面試講解
歡迎與我聯絡

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2141852/,如需轉載,請註明出處,否則將追究法律責任。

相關文章