Oracle goldengate搭建ogg

分類:存儲 時間:2017-01-20
主庫:
1.檢查是否開啟歸檔
select log_mode from gv$database;
archive log list;    ----註意歸檔路徑需要是共享路徑

2.檢查是否開啟force logging及補充日誌
select force_logging,supplemental_log_data_min,supplemental_log_data_all,flashback_on from v$database;
開啟:
alter database force logging;
alter database add supplemental log data;
alter system archive log current;

3.對主庫檢查,ogg不允許:唯一索引的索引列的列定義允許為null的
select dic.table_owner,
       dic.table_name,
       dic.index_name,
       di.uniqueness,
       dic.column_name
  from dba_ind_columns dic, dba_indexes di, dba_tab_columns dtc
 where dic.table_owner = '自行添加用戶' -----修改用戶名
   and dtc.OWNER = '自行添加用戶' -----修改用戶名
   AND dic.table_owner = di.table_owner
   and dic.TABLE_NAME = di.table_name
   and dic.index_name = di.index_name
   and di.uniqueness = 'UNIQUE'
   and dtc.owner = di.table_owner
   and dtc.TABLE_NAME = di.table_name
   and dic.column_name = dtc.COLUMN_NAME
   and dtc.nullable = ' Y '
   and dic.TABLE_NAME = dtc.TABLE_NAME;
不應該返回行,如果返回了,修改:要麽變為非唯一索引,要麽在保留唯一索引的情況下,將列的定義置為 not null。

4.創建ogg用戶,並授權
create user goldengate identified by goldengate default tablespace users;
grant dba to goldengate;
ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;

5.設置環境變量(Oracle用戶)
PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin:/ggs
export LD_LIBRARY_PATH=/ggs:$ORACLE_HOME/lib

6.檢查是否有nologing方式的表(ogg不支持nologing方式創建的表)
select owner,table_name,logging from dba_tables where logging='NO' AND owner='用戶名';
修改為logging的表的語法:alter table 表名 logging;
註意:在ext進程的參數文件裏添加 dboptions allownologging可以讓ext進程繼續運行,但是會導致數據丟失。

7.兩個節點上傳ogg介質並解壓,授權/ggs目錄給oracle
chown oracle:dba /ggs -R
su - oracle
cd /ggs
unzip p22575475_1121032_linux-x86-64.zip
tar xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

8.源端數據庫添加表的補充日誌
進入ogg安裝路徑:
cd /ggs
ggsci
dblogin userid goldengate password goldengate
create subdirs
add trandata lm.testogg

9.配置DDL復制
使用goldengate作為存儲DDL objects的用戶
給goldengate授權:
GRANT EXECUTE ON UTL_FILE TO goldengate;

10.配置GLOBALS文件
ggsci
edit param ./GLOBALS中加入:
GGSCHEMA goldengate

11.如果是10g需要停用 recyclebin,11g就不需要了

12.數據庫執行:
退出所有的oracle連接後執行:
cd /ggs
sqlplus / as sysdba
@marker_setup.sql
@ddl_setup.sql
Please move GOLDENGATE to its own tablespace
 @role_setup.sql
grant ggs_ggsuser_role to goldengate;
 @ddl_enable.sql

13.如果是有災備演練的需求,需要配置sequence同步
cd /ggs   --ogg安裝目錄
sqlplus / as sysdba
@sequence.sql
GRANT EXECUTE on goldengate.updateSequence TO goldengate;

14.源端配置參數文件
su - grid
vi $ORACLE_HOME/Network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
 (SID_DESC =
  (GLOBAL_DBNAME = +ASM)
  (ORACLE_HOME=/u01/app/11.2.0/grid)
  (SID_NAME = +ASM1)
 )
)


su - oracle
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
ASM =
 (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 186.168.100.3)(PORT = 1521))
    (CONNECT_DATA =
      http://www.ithao123.cn/(SERVER = DEDICATED)
      (SERVICE_NAME = +ASM)
      (SID_NAME = +ASM1)
    )
  )


MGR:
ggsci
 edit params mgr
======================================
port 7809
-- DYNAMICPORTLIST 7830-7835
autostart extract *
autorestart extract *, waitminutes 1, retries 60, RESETMINUTES 60
PURGEOLDEXTRACTS /ggs/dirdat/sd*, USECHECKPOINTS, MINKEEPHOURS 2
======================================
EXT:
add extract extfull, tranlog,threads 2,begin now       ----主庫為rac兩個節點,如果是單機,不需要threads
edit param extfull
=================================================
extract extfull
setenv ( NLS_LANG = " AMERICAN_AMERICA.ZHS16GBK " )
TRANLOGOPTIONS ASMUSER SYS@ASM, ASMPASSWORD oracle
THREADOPTIONS MAXCOMMITPROPAGATIONDELAY 80000 IOLATENCY 160000

DBOPTIONS ALLOWUNUSEDCOLUMN

userid goldengate, password goldengate

ddl include mapped

ddloptions addtrandata RETRYOP MAXRETRIES 1000 RETRYDELAY 10, REPORT

WARNLONGTRANS 1h, CHECKINTERVAL 5m
--每5分鐘檢測一次,對運行時間超過1小時的長事務,gg會記入抽取進程.rpt和ggserr.log,此參數為抽取進程的參數。

exttrail /ggs/dirdat/sd
gettruncates
dynamicresolution

NOCOMPRESSUPDATES

NOCOMPRESSDELETES

--tableexclude'CIMS.cncdata';
--DDLERROR _SKIPDDL 738310

table LM.testogg;

--sequence CHARISMA_DEMO.*;
===============================================

15.添加trial文件,每個50M
add exttrail  /ggs/dirdat/sd, extract extfull, MEGABYTES 50

16.添加傳輸進程
add extract dpfull exttrailsource /ggs/dirdat/sd

17.創建遠程隊列文件並將其指定給傳輸進程
add rmttrail /ggs/dirdat/td, extract dpfull, MEGABYTES 50

18.配置傳輸進程參數
edit param dpfull
==================================
extract dpfull
passthru
rmthost 186.168.100.22, mgrport 7809
rmttrail /ggs/dirdat/td
gettruncates

table LM.testogg;
--sequence CIMS.*;
===================================

19.從源端去一次scn號   
select current_scn from v$database;       --

20.按照上面查詢出的scn導出數據
expdp  sys/****** directory=  dumpfile=%U.dmp logfile=.log schemas=  parallel= flashback_scn=scn

21.啟動mgr及抓取傳輸進程


備庫:
1.創建ogg用戶並授權
create user goldengatet identified by goldengatet default tablespace tbs_ogg;
grant dba to goldengatet;
exec dbms_streams_auth.grant_admin_privilege(grantee => 'GOLDENGATET',grant_privileges => true);
ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;

2.配置環境變量(oracle用戶下)
export LD_LIBRARY_PATH=/ggs:$ORACLE_HOME/lib
export PATH=$HVR_HOME/bin:$PATH:$ORACLE_HOME/bin:$PATH:$HOME/bin:/ggs

3.兩個節點上傳ogg介質並解壓,授權/ggs目錄給oracle
chown oracle:dba /ggs -R
su - oracle
cd /ggs
unzip p22575475_1121032_Linux-x86-64.zip
tar xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

4.創建ogg相關路徑
進入ogg安裝路徑:
cd /ggs
ggsci
dblogin userid goldengatet password goldengatet
create subdirs

5.如果配置sequence,需要
cd /ggs   --ogg安裝目錄
sqlplus / as sysdba
@sequence.sql
GRANT EXECUTE on goldengatet.replicateSequence TO goldengatet;

6.配置參數文件
MGR:
edit param mgr
======================================
port 7809
autostart replicat *
autorestart replicat *, waitminutes 1, retries 60, RESETMINUTES 60
PURGEOLDEXTRACTS /ggs/dirdat/td*, USECHECKPOINTS, MINKEEPHOURS 2
======================================

7.添加checkpoint表
dblogin userid goldengate,password goldengate
ADD CHECKPOINTTABLE goldengate.ckptfull

8.添加目標端應用進程
add replicat repfull, exttrail /ggs/dirdat/td, CHECKPOINTTABLE goldengate.ckptfull
 
9.修改目標端應用進程參數
 edit params repfull
====================================================
replicat repfull
setenv ( NLS_LANG =  "AMERICAN_AMERICA.ZHS16GBK" )

assumetargetdefs

userid goldengate, password goldengate

DBOPTIONS DEFERREFCONST, SUPPRESSTRIGGERS
gettruncates
ALLOWNOOPUPDATES
ddl include mapped

discardfile ./dirrpt/repfull.dsc, append, megabytes 5000

--DDLERROR 30568,IGNORE
--REPERROR 1403, DISCARD
--mapexclude CIMS.TJ_QY_NZ3_SUB;
map lm.testogg, target lm.testogg;
========================================
啟動目標端應用進程前需要確認的事情:
第一,    在rep參數文件中有參數DEFERREFCONST禁用級聯刪除
第二,    在rep參數文件中有參數SUPPRESSTRIGGERS 在rep進程運行時抑制目的端數據庫的觸發器生效。
註意:SUPPRESSTRIGGERS此參數僅僅對10.2.0.5 及以後,11.2.0.2及以後的oracle 數據庫版本才有效,所以,若是目的端數據庫是10.2.0.4,還需要在目的端數據庫中手工禁用觸發器(用plsql dev就可以禁用)
第三,    Impdp已經導入完成

11.導入數據
impdp sys/aaa directory=dumpfile=.dmp tables=    exclude=statistics

12.收集統計信息
exec dbms_stats.gather_table_stats(OWNNAME => ‘LM’, TABNAME => ‘TESTOGG’, CASCADE => TRUE);

11.啟動應用進程
start mgr
start repfull, aftercsn scn               ---源端取到的scn


Tags:

文章來源:


ads
ads

相關文章
ads

相關文章

ad