1. 程式人生 > >oracle 11.2.0.4安裝配置goldengate 12.3.0.14 並配置表級初始化 (僅針對DML)

oracle 11.2.0.4安裝配置goldengate 12.3.0.14 並配置表級初始化 (僅針對DML)

一、環境介紹

source:

Redhat 6.10 + oracle 11.2.0.4 + ogg 12.3.0.14 

target:

Redhat 6.10 + oracle 11.2.0.4 + ogg 12.3.0.14

二、安裝goldengate軟體

三、檢查源端資料庫是否為歸檔模式

四、檢查資料庫的附加日誌是否開啟

SQL> Select SUPPLEMENTAL_LOG_DATA_MIN,

 SUPPLEMENTAL_LOG_DATA_PK,

SUPPLEMENTAL_LOG_DATA_UI,

 SUPPLEMENTAL_LOG_DATA_FK,

 SUPPLEMENTAL_LOG_DATA_ALL from v$database

;

SUPPLEME SUP SUP SUP SUP

-------- --- --- --- ---

YES      NO NO NO NO  ---------未開啟,需要更改

開啟附加日誌並切換日誌(保證Online redo log和Archive log一致)

alter database add supplemental log data ;

alter database add supplemental log data (primary key, unique,foreign key) columns;

alter system switch logfile;

再次使用以下sql語句檢查資料庫附加日誌的開啟狀況

SQL>Select

SUPPLEMENTAL_LOG_DATA_MIN,

SUPPLEMENTAL_LOG_DATA_PK,

SUPPLEMENTAL_LOG_DATA_UI,

SUPPLEMENTAL_LOG_DATA_FK,

SUPPLEMENTAL_LOG_DATA_ALL from v$database;

SUPPLEME SUP SUP SUP SUP

-------- --- --- --- ---

YES      YES YES YES NO

注:確保最小附加日誌,pk,uk,fk附加日誌開啟。而all columns的附加日誌關閉;

五、檢查資料庫是否開啟強制日誌

SQL> select force_logging from v$database;檢視是否開啟強制日誌

FOR

---

NO

SQL>

SQL>alter database force logging;

六、source建立goldengate使用者和表空間

create tablespace goldengate datafile 'xxxx' size 100M autoextend on next 5M;

create user goldengate identified by goldengate default goldengate;

grant connect,resource,dba to goldengate

create temporary tablespace temp01 tempfile '/xxxx/temp01.dbf' size 100M autoextend on next 50M;

alter database default temporary tablespace temp01;

七、新增表級附加日誌

GGSCI > dblogin userid goldengate,password goldengate;

GGSCI > info trandata SCHEMA.TABLE

GGSCI > add trandata SCHEMA.TABLE

八、配置MGR程序引數

如下:

PORT 7809 AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 7 PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 7 LAGREPORTHOURS 1 LAGINFOMINUTES 30 LAGCRITICALMINUTES 45

八、新增抽取程序引數

如下:

EXTRACT extya SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK") USERID goldengate, PASSWORD goldengate REPORTCOUNT EVERY 30 MINUTES, RATE DISCARDFILE ./dirrpt/extya.dsc, APPEND, MEGABYTES 1024 DISCARDROLLOVER AT 3:00 --WARNLONGTRANS 2h, CHECKINTERVAL 3m EXTTRAIL ./dirdat/ya DYNAMICRESOLUTION DBOPTIONS  ALLOWUNUSEDCOLUMN FETCHOPTIONS NOUSESNAPSHOT TRANLOGOPTIONS  EXCLUDEUSER goldengate

TABLE SCOTT.*; ~               

九、配置傳輸程序引數

如下:

EXTRACT dpeya RMTHOST 192.168.127.67, MGRPORT 7809, COMPRESS PASSTHRU RMTTRAIL ./dirdat/ya DYNAMICRESOLUTION

TABLE    SCOTT.*;

十、新增抽取/傳輸程序與佇列檔案

GGSCI>ADD EXTRACT extya, TRANLOG, BEGIN NOW threads 2  ----rac 環境

GGSCI>ADD EXTRACT extya, TRANLOG, BEGIN NOW 

GGSCI>ADD EXTTRAIL ./dirdat/ya, EXTRACT extya

GGSCI>ADD EXTRACT dpeya, EXTTRAILSOURCE ./dirdat/ya

GGSCI>ADD RMTTRAIL ./dirdat/ya, EXTRACT dpeya, MEGABYTES 200

十一、啟動source端mgr程序與抽取程序

GGSCI> start mgr

GGSCI> start extya

啟動抽取程序如果遇到如下錯誤:

ERROR   OGG-02091  Oracle GoldenGate Delivery for Oracle, repya.prm:  Operation not supported because enable_goldengate_replication is not set to true.

解決辦法:    SQL> ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;

System altered.

SQL>

十二、source使用expdp/impdp實施goldengate初始化(推薦使用rman,我這裡只是為了測試所以使用了資料泵)

建立資料目錄:

[[email protected]_ogg dirdat]# mkdir /u02 [[email protected]_ogg dirdat]# chown -R oracle:oinstall /u02 [[email protected]_ogg dirdat]# chmod -R 775 /u02

create directory dbdata as '/u02';

grant read,write on directory dbdata to goldengate;

SQL> select current_scn from v$database;

CURRENT_SCN -----------     1003952

SQL>

[[email protected]_ogg Disk1]$ expdp \'/ as sysdba\' directory=dbdata dumpfile=%U7788.dmp filesize=1G parallel=2 exclude=grant,statistics,trigger full=y flashback_scn=1003952 logfile=data7.log

十三、將source端資料傳到target端,匯入資料庫

impdp \'/ as sysdba\' directory=dbdata dumpfile=%U7788.dmp parallel=2 table_exists_action=truncate full=y logfile=dbdata7788.log

十四、target安裝OGG軟體

十五、target建立OGG使用者和表空間及temp表空間

create tablespace goldengate datafile 'xxxx' size 100M autoextend on next 5M;

create user goldengate identified by goldengate default goldengate;

grant connect,resource,dba to goldengate

create temporary tablespace temp01 tempfile '/xxxx/temp01.dbf' size 100M autoextend on next 50M;

alter database default temporary tablespace temp01;

十六、target禁用觸發器和外來鍵約束

禁用觸發器:

SQL>declare

v_sql varchar2(2000);

CURSOR c_trigger IS SELECT 'alter trigger '||owner||'.'||trigger_name||' disable' from dba_triggers where owner in ('SCOTT');

BEGIN

OPEN c_trigger;

LOOP

FETCH c_trigger INTO v_sql;

EXIT WHEN c_trigger%NOTFOUND;

execute immediate v_sql;

end loop;

close c_trigger;

end;

/

檢視結果:

select owner||'.'||trigger_name,status from dba_triggers where owner='SCOTT' and STATUS='ENABLED';

禁用外來鍵約束:

SQL>declare

v_sql varchar2(2000);

CURSOR c_trigger IS SELECT 'alter table '||owner||'.'||table_name||' disable constraint '||constraint_name from dba_constraints where constraint_type='R' and owner in ('SCOTT');

BEGIN

OPEN c_trigger;

LOOP

FETCH c_trigger INTO v_sql;

EXIT WHEN c_trigger%NOTFOUND;

execute immediate v_sql;

end loop;

close c_trigger;

end;

/

檢視結果:

select status, owner||'.'||table_name from dba_constraints where owner='SCOTT' and status='ENABLED' and  constraint_type='R';

十七、停用JOB

SQL> select job,log_user from dba_jobs;

conn /as sysdba

SQL>exec dbms_ijob.broken(299,true);

十八、編輯GLOBALS引數檔案

GGSCI>EDIT PARAMS ./GLOBALS

CHECKPOINTTABLE goldengate.checktable

十九、新增checkpointtable

GGSCI>dblogin userid goldengate,password goldengate

GGSCI>add checkpointtable goldengate.checktable

二十、target配置mgr引數

PORT 7809 STARTUPVALIDATIONDELAY 5 AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 7 PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 7 LAGREPORTHOURS 1 LAGINFOMINUTES 30 LAGCRITICALMINUTES 45

二十一、target配置replication引數

EPLICAT repya USERID goldengate, PASSWORD goldengate SETENV (NLS_LANG = "AMERICAN_AMERICA.AL32UTF8") SQLEXEC "ALTER SESSION SET CONSTRAINTS=DEFERRED" REPORT AT 06:00 REPORTCOUNT EVERY 25 MINUTES, RATE REPORTROLLOVER AT 02:00 REPERROR DEFAULT, ABEND ALLOWNOOPUPDATES --DISCARDFILE ./dirrpt/repya.dsc, APPEND, MEGABYTES 1024M DISCARDFILE ./dirrpt/repya.dsc DISCARDROLLOVER AT 02:30 ALLOWNOOPUPDATES

MAP  SCOTT.*,   TARGET   SCOTT.*;

二十二、新增複製程序

ggsci>ADD REPLICAT repya, EXTTRAIL ./dirdat/ya,CHECKPOINTTABLE goldengate.checktable

二十三、source端開啟投遞程序,target端檢視是否有佇列檔案傳輸過來

二十四、target開啟複製程序

ggsci> start repya aftercsn 1003952

*************************************************************************************************************************************************

                                                                                    OGG單表初始化步驟

*************************************************************************************************************************************************

1、停止target端的複製程序

GGSCI> stop repya

2、獲取當前source端的scn號

select dbms_flashback.get_system_change_number from dual;

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER ------------------------          1054979

SQL>

3、source匯出要同步的表

expdp system/oracle directory=dbdata dumpfile=test.dmp logfile=1.log tables=scott.aa flashback_scn=1054979

4、source端試著執行dml操作

SQL> delete from scott.aa where ename='KING';

6 rows deleted.

SQL> commit;

Commit complete.

SQL> 

SQL> update scott.aa set sal=0 where ename='SCOTT';

6 rows updated.

SQL> commit;

Commit complete.

SQL>

SQL> insert into scott.aa select * from scott.emp;

14 rows created.

SQL> commit;

Commit complete.

SQL>

5、target匯入

impdp system/oracle directory=dbdata dumpfile=test.dmp tables=scott.aa  table_exists_action=replace

6、target編輯replication配置引數

加入如下內容:

map SCOTT.aa, target SCOTT.aa, filter (@GETENV('transaction','csn') > 1054979);

replication配置引數如下:

REPLICAT repya USERID goldengate, PASSWORD goldengate SETENV (NLS_LANG = "AMERICAN_AMERICA.AL32UTF8") SQLEXEC "ALTER SESSION SET CONSTRAINTS=DEFERRED" REPORT AT 06:00 REPORTCOUNT EVERY 25 MINUTES, RATE REPORTROLLOVER AT 02:00 REPERROR DEFAULT, ABEND ALLOWNOOPUPDATES --DISCARDFILE ./dirrpt/repya.dsc, APPEND, MEGABYTES 1024M DISCARDFILE ./dirrpt/repya.dsc DISCARDROLLOVER AT 02:30 ALLOWNOOPUPDATES

map SCOTT.aa, target SCOTT.aa, filter (@GETENV('transaction','csn') > 1054979);

------ 如果使用的11g的ogg,需要使用雙引號"transaction","csn",如果使用的是12c的ogg使用單引號

MAP  SCOTT.*,   TARGET   SCOTT.*; 7、啟動repya程序

GGSCI> start repya

8、等待延時追平後(資料同步完成),再停止複製程序,登出單表同步內容

--map SCOTT.aa, target SCOTT.aa, filter (@GETENV('transaction','csn') > 1054979);

9、再次啟動複製程序即可