兩臺服務(wù)器都需要創(chuàng)建ogg操作系統(tǒng)用戶(此步驟非必須,也可以使用ORACLE用戶安裝)。
useradd -u 1003 -g oinstall -G dba ogg
passwd ogg
十余年的平桂網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都全網(wǎng)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整平桂建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“平桂網(wǎng)站設(shè)計”,“平桂網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
su - ogg
vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=XXL1
export LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/dbhome_1/lib
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/jdk/bin:$PATH
export GGHOLE=/ogg
source .bash_profil生效
兩臺服務(wù)器都需要做同樣的操作。
mkdir /ogg
chown -R ogg:oinstall /ogg
將ogg的11g安裝包fbo_ggs_Linux_x64_ora11g_64bit.tar上傳到/ogg下
用ogg用戶解壓
tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar
./ggsci測試
[ogg@oracle2 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (oracle2) 1>
ORACLE建議使用單獨的表空間存放OGG數(shù)據(jù),表空間大小50M就可以,但是最好設(shè)置數(shù)據(jù)文件的自動擴展。
select file_name from dba_data_files;查看表空間的存放目錄
create tablespace ogg datafile ‘/u01/app/oracle/oradata/XXL/ogg01.dbf’ size 50M autoextend on;
創(chuàng)建OGG用戶
create user ogg identified by ogg default tablespace ogg;
為OGG用戶授權(quán),OGG用戶需要以下權(quán)限,也有人為了省事,直接給OGG用戶DBA權(quán)限。
grant CONNECT, RESOURCE to ogg;
grant SELECT ANY DICTIONARY, SELECT ANY TABLE to ogg;
grant ALTER ANY TABLE to ogg;
grant FLASHBACK ANY TABLE to ogg;
grant EXECUTE on DBMS_FLASHBACK to ogg;
grant insert any table to ogg;
grant update any table to ogg;
grant delete any table to ogg;
不同的需求,OGG用戶需要的權(quán)限也不一樣,上面的權(quán)限基本可以支持大多數(shù)情況的數(shù)據(jù)復(fù)制,如上面的權(quán)限不足,需根據(jù)實際需求授權(quán)。
打開數(shù)據(jù)庫的附加日志和force log
SQL> select NAME,OPEN_MODE,FORCE_LOGGING,SUPPLEMENTAL_LOG_DATA_MIN from v$database;
NAME OPEN_MODE FOR SUPPLEME
——— ——————– — ——–
DBDREAM READ WRITE NO NO
上面顯示數(shù)據(jù)庫的附加日志和force log都沒有開啟,使用下面的命令開啟。
SQL> alter database force logging;
Database altered.
SQL> alter database add SUPPLEMENTAL log data;
Database altered.
SQL> select NAME,OPEN_MODE,FORCE_LOGGING,SUPPLEMENTAL_LOG_DATA_MIN from v$database;
NAME OPEN_MODE FOR SUPPLEME
——— ——————– — ——–
DBDREAM READ WRITE YES YES
確保最小附件日志,pk,uk,fk附加日志打開,而all columns的附加日志是關(guān)閉的。
SQL> select SUPPLEMENTAL_LOG_DATA_MIN a,SUPPLEMENTAL_LOG_DATA_PK b,SUPPLEMENTAL_LOG_DATA_UI c,SUPPLEMENTAL_LOG_DATA_FK d,SUPPLEMENTAL_LOG_DATA_ALL e from v$database;
SUPPLEMENTAL_LOG SUPPLE SUPPLE SUPPLE SUPPLE
YES NO NO NO NO
SQL> alter database add supplemental log data (primary key,unique,foreign key) columns;
Database altered.
SQL> select SUPPLEMENTAL_LOG_DATA_MIN a,SUPPLEMENTAL_LOG_DATA_PK b,SUPPLEMENTAL_LOG_DATA_UI c,SUPPLEMENTAL_LOG_DATA_FK d,SUPPLEMENTAL_LOG_DATA_ALL e from v$database;
A B C D E
YES YES YES YES NO
關(guān)閉回收站功能(DDL)必須關(guān)閉
SQL> show parameter recyclebin
NAME TYPE VALUE
recyclebin string on
alter system set recyclebin=off scope=spfile;這樣就需要重啟數(shù)據(jù)庫生效
alter system switch logfile;
查看要是同步的用戶的狀態(tài),確保是open
select username,account_status from dba_users;
運行OGG支持sequence
運行OGG支持DDL腳本如果要讓OGG支持DDL操作,還需要額外運行幾個腳本,這些腳本是OGG帶的而不是ORACLE帶的,在OGG的安裝目錄都可以找到,如果在OGG的安裝目錄登錄數(shù)據(jù)庫,可以直接@加腳本的名字,源端與目標端都需要運行,如下:
br/>如果要讓OGG支持DDL操作,還需要額外運行幾個腳本,這些腳本是OGG帶的而不是ORACLE帶的,在OGG的安裝目錄都可以找到,如果在OGG的安裝目錄登錄數(shù)據(jù)庫,可以直接@加腳本的名字,源端與目標端都需要運行,如下:
@marker_setup.sql 建立一個DDL標記表 schema name:輸入ogg即可
@ddl_setup.sql 在數(shù)據(jù)庫中創(chuàng)建DDL語句的trigger等必要組件
(執(zhí)行時必須斷開ggsci,不然報錯)
@role_setup.sql 建立ggs_ggsuser_role角色
@ddl_enable.sql enable ddl捕獲觸發(fā)器
如果沒有在OGG的安裝目錄登錄數(shù)據(jù)庫,需要指定腳本的位置,比如我的OGG安裝目錄為/ogg。
sqlplus / as sysdba@/ogg/marker_setup.sql
br/>@/ogg/marker_setup.sql
br/>@/ogg/role_setup.sql
創(chuàng)建OGG的管理目錄
在正式配置OGG之前,首先需要創(chuàng)建OGG的管理目錄,源端和目標端都需要創(chuàng)建,登錄OGG,只需要執(zhí)行create subdirs命令就可以了。
源端:
[ogg@dbdream ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (dbdream) 1> create subdirs
Creating subdirectories under current directory /ogg
Parameter files /ogg/dirprm: already exists
Report files /ogg/dirrpt: created
Checkpoint files /ogg/dirchk: created
Process status files /ogg/dirpcs: created
SQL script files /ogg/dirsql: created
Database definitions files /ogg/dirdef: created
Extract data files /ogg/dirdat: created
Temporary files /ogg/dirtmp: created
Stdout files /ogg/dirout: created
目標端:
[ogg@dbdream ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (dbdream) 1> create subdirs
Creating subdirectories under current directory /ogg
Parameter files /ogg/dirprm: already exists
Report files /ogg/dirrpt: created
Checkpoint files /ogg/dirchk: created
Process status files /ogg/dirpcs: created
SQL script files /ogg/dirsql: created
Database definitions files /ogg/dirdef: created
Extract data files /ogg/dirdat: created
名字 用途
dirprm 存放OGG參數(shù)各的配置信息
dirrpt 存放進程報告文件
dirchk 存放檢查點文件
dirpcs 存放進程狀態(tài)文件
dirsql 存放SQL腳本文件
dirdef 存放DEFGEN工具生成的數(shù)據(jù)定義文件
dirdat 存放Trail文件,也就是Capture進程捕獲的日志文件
dirtmp 當事物需要的內(nèi)存超過已分配內(nèi)存時,默認存儲在這個目錄
OGG復(fù)制流程
之前所做的只是準備工作,現(xiàn)在就可以正式配置OGG了,在配置OGG之前,先看下OGG的復(fù)制流程,OGG和其他傳統(tǒng)復(fù)制軟件一樣,也是通過源端捕獲/挖掘ORACLE的日志信息,
目標端根據(jù)源端傳送過來的日志信息進行重塑,實現(xiàn)源端-目標端數(shù)據(jù)同步
只有commit之后的日志信息才會被Capture進程捕獲,未提交的事務(wù)OGG不會捕獲。
建立測試用戶并授權(quán)
create user lqh identified by lqh;
grant dba to lqh;
conn lqh/lqh
源
create table test100
(id number primary key,
name1 varchar2(20),
name2 varchar2(20),
name3 varchar2(20));
create table test200
(id number primary key,
name1 varchar2(20),
name2 varchar2(20),
name3 varchar2(20));
create table test300
(id number,
name1 varchar2(20),
name2 varchar2(20),
name3 varchar2(20));
begin
for i in 1..1000
loop
insert into test100 values (i,'name1-'||i,'name2-'||i,'name3-'||i);
insert into test200 values (i,'name1-'||i,'name2-'||i,'name3-'||i);
insert into test300 values (i,'name1-'||i,'name2-'||i,'name3-'||i);
if i mod 2 =0
then
commit;
end if;
end loop;
commit;
end;
/
目標:
create table test100
(id number primary key,
name1 varchar2(20),
name2 varchar2(20),
name3 varchar2(20));
create table test200
(id number primary key,
name1 varchar2(20),
name2 varchar2(20),
name3 varchar2(20));
create table test300
(id number,
name1 varchar2(20),
name2 varchar2(20),
name3 varchar2(20));
源端添加表級TRANDATA
添加表級的trandata可以理解為需要將哪些用戶的哪些表同步到目標庫,其實也是添加表級的supplemental log,但是只有上文打開的minimal supplemental log后,這個才生效。
用OGG用戶從OGG登錄源端數(shù)據(jù)庫。
GGSCI (dbdream) 2> DBLOGIN USERID ogg, PASSWORD ogg
Successfully logged into database.
源端添加表級TRANDATA,我們這先使用test一些表。
GGSCI (oracle1) 3> add trandata lqh.test100
Logging of supplemental redo data enabled for table LQH.TEST100.
GGSCI (oracle1) 4> add trandata lqh.test200
Logging of supplemental redo data enabled for table LQH.TEST200.
GGSCI (oracle1) 5> add trandata lqh.test300
2018-04-17 06:13:52 WARNING OGG-00869 No unique key is defined for table 'TEST300'. 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 LQH.TEST300.
成功添加表級TRANDATA后,可以通過INFO命令查看哪些表被添加了TRANDATA.
GGSCI (oracle1) 6> info trandata lqh.*
Logging of supplemental redo log data is enabled for table LQH.TEST100.
Columns supplementally logged for table LQH.TEST100: ID.
Logging of supplemental redo log data is enabled for table LQH.TEST200.
Columns supplementally logged for table LQH.TEST200: ID.
Logging of supplemental redo log data is enabled for table LQH.TEST300.
Columns supplementally logged for table LQH.TEST300: ID, NAME1, NAME2, NAME3.
查看lqh.TEST100這張表是否開啟了trandata
GGSCI (oracle1) 8> info trandata lqh.TEST100
Logging of supplemental redo log data is enabled for table LQH.TEST100.
Columns supplementally logged for table LQH.TEST100: ID.
源端添加表級附加日志
set heading off;
set pagesize 120
select 'add trandata "'||owner||'"."'||table_name||'"' from dba_tables where owner in('用戶');
dblogin userid goldengate,password **
add trandata "用戶"."表名"
add trandata?"用戶"."表名"
add trandata?"用戶"."表名"
add trandata?"用戶"."表名"
add trandata?"用戶"."表名"
info trandata ?用戶.*
配置MGR管理進程
源端:
GGSCI (dbdream) 5> EDIT PARAMS MGR
加入以下兩行內(nèi)容
PORT 7809
AUTOSTART ER
PURGEOLDEXTRACTS ./ogg/dirdat/, USECHECKPOINTS
LAGREPORTHOURS 1 ?
LAGINFOMINUTES 30 ? ?
LAGCRITICALMINUTES 45
目標端:
GGSCI (stream) 2> EDIT PARAMS MGR
加入以下兩行內(nèi)容
PORT 7809
AUTOSTART ER
PURGEOLDEXTRACTS ./ogg/dirdat/, USECHECKPOINTS
LAGREPORTHOURS 1 ?
LAGINFOMINUTES 30 ? ?
LAGCRITICALMINUTES 45
參數(shù)說明及參考:
PORT 7809:? ---OGG管理進程監(jiān)控通信端口。生產(chǎn)端和災(zāi)備端需要保持一致
AUTOSTART ER * ? ?---自動啟動進程
PURGEOLDEXTRACTS: ?---清除不需要的trail文件。
/ogg/dirdat: ?---trail文件存放位置。
USECHECKPOINTS: ?---使用檢查點隊列。
LAGREPORTHOURS 1 ? ?---每隔一小時檢查一次傳輸延遲情況
LAGINFOMINUTES 30 ? ?---傳輸延時超過30分鐘將寫入錯誤日志
LAGCRITICALMINUTES 45 ---傳輸延時超過45分鐘將寫入警告日志,既error
PURGEOLDEXTRACTS ./dirdat/, USECHECKPOINTS, MINKEEPDAYS 3 ? ?
---清除過期的tail文件,保留3天
STARTUPVALIDATIONDELAY 5 ? ?---?啟動時延遲5秒校驗
DYNAMICPORTLIST? 7840-7914 ?
?---用于與goldengate的復(fù)制進程,collector進程,ggsci命令進行通信。
AUTORESTART EXTRACT , RETRIES 5, WAITMINUTES 7 ?
----當提取進程中斷后嘗試自動重啟,每隔7分鐘嘗試啟動一次,嘗試5次,基本不用
PURGEDDLHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10,F(xiàn)REQUENCYMINUTES 30 ?
--此參數(shù)用于維護GGS_DDL_HIST表,默認清除1小時沒有變更過的記錄。此處為GGS_DDL_HIST表記錄保存7-10天內(nèi)沒有變更過的記錄
PURGEMARKERHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10 ?
--用于維護GGS_MARKER的記錄數(shù)。默認為超過1小時的記錄沒有變更即刪除。此處的參數(shù)含義為7-10天內(nèi)的記錄沒有變更,就刪除該記錄,每30分鐘檢查并執(zhí)行一次。
配置完MGR管理進程后,就可以啟動MGR管理進程(源端和目標端都需要啟動)。
GGSCI (oracle2) 6> start mgr
Manager started.
可以通過INFO命令查看進程的狀態(tài)(最好每次啟動時在兩端都查看下)。
GGSCI (oracle2) 7> info mgr
Manager is running (IP port oracle2.7809).
GGSCI (oracle1) 4> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
配置初始化數(shù)據(jù)進程
由于在創(chuàng)建測試表的時候,源端的測試表有數(shù)據(jù),而目標端的測試表只有結(jié)構(gòu),沒有數(shù)據(jù),所以需要初始化目標端的數(shù)據(jù),所謂初始化,就是讓目標端的數(shù)據(jù)和源端的數(shù)據(jù)在這個時間點是一模一樣的,所以初始化工作并不需要一定使用OGG,也可以使用EXP、EXPDP、SQLLOAD等其他工具,本文主要介紹如何使用OGG進行數(shù)據(jù)初始化,下面在源端配置捕獲進程lqh。
GGSCI (oracle1) 8> add extract lqh, SOURCEISTABLE
EXTRACT added.
查看EINI_1進程狀態(tài)。
GGSCI (oracle1) 9> INFO EXTRACT *, TASKS
EXTRACT lqh Initialized 2018-04-11 01:01 Status STOPPED
Checkpoint Lag Not Available
Log Read Checkpoint Not Available
First Record Record 0
Task SOURCEISTABLE
由于只是添加了捕獲進程lqh,還沒有進行配置和啟動這個進程,所以現(xiàn)在的狀態(tài)是STOPPED狀態(tài)。
查看數(shù)據(jù)庫字符集如下
select * from nls_database_parameters where parameter='NLS_CHARACTERSET';
select userenv('language') from dual;
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
源端編輯捕獲進程lqh。
GGSCI (oracle1) 10> EDIT PARAMS lqh
–加入以下內(nèi)容
EXTRACT lqh
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
USERID ogg PASSWORD ogg
RMTHOST oracle2 MGRPORT 7809
RMTTASK REPLICAT GROUP xixi
TABLE LQH.TEST100;
TABLE LQH.TEST200;
參數(shù)介紹:
EXTRACT lqh:說明這是EXTRACT進程,名字是lqh
SETENV:環(huán)境變量,一定要設(shè)置和數(shù)據(jù)庫字符集一樣,否則可能會亂碼
USERID:數(shù)據(jù)庫OGG用戶
PASSWORD:數(shù)據(jù)庫用戶OGG的密碼
RMTHOST:目標端地址,如果在/etc/hosts文件里已經(jīng)設(shè)置解析,可以寫主機名
MGRPORT:目標端MGR管理進程監(jiān)聽的端口
RMTTASK REPLICAT:目標端REPLICAT應(yīng)用進程的組和名字
TABLE:源端要初始化數(shù)據(jù)的表的名字
編輯好捕獲進程lqh后,還需要在目標端配置REPLICAT應(yīng)用進程,名字要和源端的捕獲進程lqh里面RMTTASK REPLICAT參數(shù)配置的一樣,也就是還需要在目標端配置RMTTASK REPLICAT lqh。
配置目標端REPLICAT進程
目標端:
GGSCI (oracle1) 8> add replicat xixi,specialrun
EXTRACT added.
查看lqh進程狀態(tài)。
GGSCI (oracle2) 7> info replicat *,task
REPLICAT XIXI Initialized 2018-04-17 06:43 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:00:11 ago)
Log Read Checkpoint Not Available
Task SPECIALRUN
GGSCI (oracle2) 9> EDIT PARAMS xixi
–加入以下內(nèi)容
REPLICAT xixi
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
ASSUMETARGETDEFS
USERID ogg PASSWORD ogg
DISCARDFILE ./dirrpt/xixi.dsc,PURGE
MAP lqh. TARGET lqh.;
此處的./dirrpt/lqh.dsc一定要這樣寫,否則會報OGG-01091錯誤。
之前寫的目錄是./ogg/dirrpt/xixi.ds,報錯如下
ERROR OGG-01091 Unable to open file "./ogg/dirrpt/xixi.dsc" (error 2, No such file or directory).
參數(shù)介紹:
REPLICAT xixi:說明這是REPLICAT應(yīng)用進程,名字叫xixi
SETENV:語言變量,同捕獲進程xixi
ASSUMETARGETDEFS:告訴OGG目標端和源端需要同步的表的結(jié)構(gòu)完全一致,不需要OGG去檢查表的結(jié)構(gòu),包括表名、字段名、字段類型、字段長度等,如果目標端和源端同步的表的結(jié)構(gòu)不一樣,需要使用SOURCEDEFS參數(shù),詳見OGG官方文檔。
USERID:數(shù)據(jù)庫OGG用戶
PASSWORD:數(shù)據(jù)庫用戶OGG的密碼
DISCARDFILE:錯誤信息存放位置及命名規(guī)則
MAP:源端捕獲的表的名字
TARGET:目標端同步的表的名字,可以不在同一SCHEMA。
初始化數(shù)據(jù)
配置好目標端的應(yīng)用進程lqh后,就可以啟動源端的捕獲進程進行捕獲數(shù)據(jù)了,而目標端的應(yīng)用進程lqh不需要手動去啟動,也就是說目標端lqh進程不需要管。
GGSCI (oracle1) 11> START EXTRACT lqh
Sending START request to MANAGER ...
EXTRACT LQH starting
GGSCI (oracle1) 17> view report lqh
2018-04-17 06:45:18 INFO OGG-03035 Operating system character set identified as UTF-8. Locale: en_US, LC_ALL:.
EXTRACT lqh
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
Set environment variable (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
USERID ogg PASSWORD ***
RMTHOST oracle2 MGRPORT 7809
RMTTASK REPLICAT GROUP xixi
TABLE LQH.TEST100;
Using the following key columns for source table LQH.TEST100: ID.
啟動源端的捕獲進程lqh后,正常情況下(如果配置沒問題),源端的數(shù)據(jù)已經(jīng)傳送到目標端了,可以通過VIEW命令查看源端捕獲進程lqh的工作狀態(tài)。
如果看不到數(shù)據(jù)而且沒有報錯,可以再次重啟一遍抽取進程 。
有數(shù)據(jù)就說明同步成功了,同步完成后服務(wù)會自動停止(下面狀態(tài)是正常的)
GGSCI (oracle1) 33> info extract lqh
EXTRACT LQH Last Started 2018-04-12 23:49 Status ABENDED
Checkpoint Lag Not Available
Log Read Checkpoint Table LQH.TEST100
2018-04-12 23:49:26 Record 1
Task SOURCEISTABLE
如果在上面日志的最后部分出現(xiàn)ERROR,就需要去檢查OGG的安裝目錄下的ggserr.log日志,這個日志相當于數(shù)據(jù)庫的告警日志。
以上我們的數(shù)據(jù)就都傳輸?shù)侥繕硕肆?,但是dml語句是傳輸不過去的,需要配置數(shù)據(jù)源庫的捕獲和傳輸進程
GGSCI (oracle1) 21> edit params caplqh
–加入以下內(nèi)容
--capture change from oracle1 to oracle2
EXTRACT caplqh
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
USERID ogg, PASSWORD ogg
EXTTRAIL ./dirdat/qh
TABLE lqh.test100;
TABLE lqh.test200;
其中,EXTTRAIL是指抽取跟蹤存放的數(shù)據(jù)位置。qh是文件的開頭字母前綴(該前綴只能
是2個字母) 。
生成ogguser的密碼暗文:
GGSCI (oracle2) 6> ENCRYPT PASSWORD ogg BLOWFISH ENCRYPTKEY DEFAULT
Using default key...
Encrypted password: AACAAAAAAAAAAADAHBLDCCIIOIRFNEPB
Algorithm used: BLOWFISH
在配置好之后修改密碼記得重新啟動進程
Caplqh捕獲進程參數(shù)
EXTRACT <進程名> ??
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK") ?設(shè)置字符集
USERID goldengate, PASSWORD AACAAAAAAAAAAGAIF, ENCRYPTKEY default ??用戶名密碼
REPORTCOUNT EVERY 30 MINUTES, RATE ? ? ---每30分鐘報告一次已經(jīng)處理的統(tǒng)計數(shù)字
DISCARDFILE ./dirrpt/exta.dsc, APPEND, MEGABYTES 256 ? ---處理中有出錯寫入到次文件
DISCARDROLLOVER AT 3:00 ? ---設(shè)定每天3點切換隊列時間
WARNLONGTRANS 2h, CHECKINTERVAL 3m ??
---每隔3分鐘檢查一下大事務(wù),超過2小時還沒結(jié)束的進行報告
EXTTRAIL ./dirdata/ya, MEGABYTES 256 ? ---指定寫入到哪個隊列
DYNAMICRESOLUTION ? ???---動態(tài)解析表名,表多的時候不用從數(shù)據(jù)庫中取出表結(jié)構(gòu)
DBOPTIONS? ALLOWUNUSEDCOLUMN ?
---在生產(chǎn)端庫表中存在unused列時,需要配置該參數(shù)。用于阻止抽取進程抽取數(shù)據(jù)時由于表含有unused列而導(dǎo)致進程abend。即使使用該參數(shù),抽取進程抽取到unused列時也會向日志文件記錄一條警告信息。
FETCHOPTIONSNOUSESNAPSHOT ?
---默認值為usesnapshot,表示利用數(shù)據(jù)庫閃回讀取數(shù)據(jù)。Nousesnapshot表示直接從原表讀取相關(guān)數(shù)據(jù)。
TRANLOGOPTIONS? CONVERTUCS2CLOBS
?---在解析數(shù)據(jù)庫日志時所需要的特殊參數(shù),CLOB字段。此參數(shù)已經(jīng)v11版本后已經(jīng)作廢
tranlogoptionsasmusersys@asm, asmpasswordAACAAAAAAAAAAGAIF, ENCRYPTKEY default?
TRANLOGOPTIONS altarchivelogdest primary instance rac1? /arch2 altarchivelogdest? instance? rac2 /arch3 ?
---rac使用,解決歸檔路徑不一致的問題;可以在一個實例上面配置多個歸檔路徑,需要保證goldengate能同時讀到各節(jié)點的歸檔,一般采用NFS掛載rac另外節(jié)點的歸檔。
THREADOPTIONS?? MAXCOMMITPROPAGATIONDELAY 60000 ? THREADOPTIONS???IOLATENCY 1000?
---?RAC集群中的所有節(jié)點必須同步系統(tǒng)時鐘。GoldenGate通過比較本地系統(tǒng)的時間和事務(wù)提交的時間點來做出關(guān)鍵決策??梢酝ㄟ^NTP來不同系統(tǒng)時間。所有節(jié)點上的COMPATIBLE參數(shù)設(shè)置也必須相同。這個參數(shù)在Oracle11.2版本后就不在使用了。
TRANLOGOPTIONS rawdevice offset 0 ?---裸設(shè)備使用
TRANOPTIONS EXCLUDEUSER goldengate ?---排除goldengate用戶
--DDL參數(shù)區(qū)域,所有復(fù)制對象,屏蔽對象在源端體現(xiàn)。
DDL &
INCLUDE MAPPED OBJTYPE 'TABLE' &
INCLUDE MAPPED OBJTYPE 'INDEX' &
INCLUDE MAPPED OBJTYPE 'SEQUENCE' &
INCLUDE MAPPED OBJTYPE 'VIEW' &
INCLUDE MAPPED OBJTYPE 'PROCEDURE' &
INCLUDE MAPPED OBJTYPE 'FUNCTION' &
INCLUDE MAPPED OBJTYPE 'PACKAGE' &? ?---標紅參數(shù)為應(yīng)用級災(zāi)備新添加的復(fù)制內(nèi)容
EXCLUDE OPTYPE COMMENT
DDLOPTIONS? addtrandata ?REPORT
--匹配table/index/sequence/view/procedure/function/package對象進行DDL復(fù)制。此處參數(shù)為按對象類型進行匹配復(fù)制
TABLE SCHEMA.; ? ---需要復(fù)制的對象列表
Sequence schema.; ? ?---需要復(fù)制的sequence對象
GGSCI (oracle1) 22> add extract caplqh,tranlog,begin now
EXTRACT added.
add extract ext_app, tranlog, begin now, threads 2?
單實例不需要加 add extract threads 子句;多于兩個實例的RAC庫, threads 子句指明實際的線程數(shù)
GGSCI (oracle1) 23> add exttrail ./dirdat/qh,extract caplqh,megabytes 5
EXTTRAIL added.
意思是將lqh捕獲的extract跟蹤文件添加到./dirdat 目錄,文件最大5M。
add EXTTRAIL ./dirdat/r1, extract ext_app,MEGABYTES 100?
GGSCI (oracle1) 10> start extract caplqh
Sending START request to MANAGER ...
EXTRACT CAPLQH starting
GGSCI (oracle1) 18> info extract caplqh
EXTRACT CAPLQH Last Started 2018-04-17 06:51 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:02 ago)
Log Read Checkpoint Oracle Redo Logs
2018-04-17 06:50:59 Seqno 75, RBA 41052160
SCN 0.913524 (913524)
GGSCI (oracle1) 12> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING CAPLQH 00:00:00 00:00:00
配置投遞(傳輸跟蹤文件)的pump進程
GGSCI (oracle1) 18> edit params pumplqh
內(nèi)容如下:
--pump file from oracle1 to oracle2
EXTRACT pumplqh
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
PASSTHRU
RMTHOST oracle2 MGRPORT 7809
RMTTRAIL ./dirdat/md
TABLE lqh.test100;
TABLE lqh.test200;
~
GGSCI (oracle1) 41> add extract pumplqh,exttrailsource ./dirdat/qh
EXTRACT added.
以上是和caplqh一致,qh命名必須和抽取保持一致
datapump進程參數(shù)
EXTRACT <進程名>
RMTHOST IP地址, MGRPORT 7809, COMPRESS ?
---目標端的ip地址,7809為目標端的管理端口,要求配置compress壓縮參數(shù),節(jié)省網(wǎng)絡(luò)帶寬,但會增加CPU開銷
PASSTHRU ?
---傳輸進程直接跟抽取進程交互,而不再和數(shù)據(jù)庫進行交互,減少數(shù)據(jù)庫資源的利用
NUMFILES 5000 ?---最多處理多少個表
RMTTRAIL ./dirdata/ya ? ---投遞哪個隊列,必須和抽取保持一致
DYNAMICRESOLUTION ? ? ---動態(tài)解析表名
TABLE schema.; ?? ---需要投遞的對象列表
Sequence schema.; ?? ---需要投遞的sequence對象
如果添加錯,下面命令刪除
GGSCI (oracle1) 5> DELETE extract pumplqh
我們把qh開頭的跟蹤文件發(fā)送到目標庫。然后設(shè)置對方的接收路徑,并且文件以pu開
頭 ,最大5M 。
GGSCI (oracle1) 14> info extract pumplqh
EXTRACT PUMPLQH Initialized 2018-04-13 01:56 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:00:09 ago)
Log Read Checkpoint File ./dirdat/qh000000
First Record RBA 0
GGSCI (oracle1) 43> add rmttrail ./dirdat/md,extract pumplqh,megabytes 5
RMTTRAIL added.
以上是和pumplqh一致
GGSCI (oracle1) 18> delete extract pumplqh2
Deleted EXTRACT PUMPLQH1.
如果添加錯這樣刪除
GGSCI (oracle1) 44> start extract pumplqh
Sending START request to MANAGER ...
EXTRACT PUMPLQH starting
配置目標庫的恢復(fù)進程
GGSCI (oracle2) 17> edit params ./GLOBALS
其中的GLOBAS必須大寫 。該文件內(nèi)容是:
checkpointtable ogg.ggschkpt
GGSCI (oracle2) 18> view params ./GLOBALS
checkpointtable ogg.ggschkpt
也就是添加檢查點表(實現(xiàn)斷點續(xù)傳) ,配置完成后必須退出重連,讓參數(shù)生效。
GGSCI (oracle2) 19> quit
[ogg@oracle2 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (oracle2) 1> dblogin userid ogg password ogg
Successfully logged into database.
GGSCI (oracle2) 2> add checkpointtable
No checkpoint table specified, using GLOBALS specification (ogg.ggschkpt)...
Successfully created checkpoint table ogg.ggschkpt.
[oracle@oracle2 ~]$ sqlplus ogg/ogg
SQL*Plus: Release 11.2.0.1.0 Production on Tue Apr 17 07:14:13 2018
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
GGSCHKPT TABLE
GGSCHKPT_LOX TABLE
GGSCI (oracle2) 3> add replicat mrpxixi exttrail ./dirdat/md
REPLICAT added.
此處和oracle1的pumplqh一致
GGSCI (oracle2) 4> edit params mrpxixi
REPLICAT mrpxixi
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
ASSUMETARGETDEFS
HANDLECOLLISIONS
USERID ogg PASSWORD ogg
DISCARDFILE ./dirrpt/mrpxixi.dsc,PURGE
MAP lqh.test100, TARGET lqh.test100;
MAP lqh.test200, TARGET lqh.test200;
其中的HANDLECOLLISIONS參數(shù)如果update 命中就insert,delete沒命中就不操作,
insert如果存在而且不能重復(fù)就變成修改數(shù)據(jù),如果存在允許重復(fù)就插入新的。如果沒這個
參數(shù)遇到上述情況會報錯。ASSUMETARGETDEFS假定數(shù)據(jù)源表的結(jié)構(gòu)和目標表相同
創(chuàng)建replicat進程
dblogin userid goldengate,password goldengate
add checkpointtable goldengate.chktable
add replicat ?reppa,exttrail ./dirdat/r1,checkpointtable goldengate.chktable
配置目標段復(fù)制進程參數(shù)
REPLICAT <進程名>
USERIDgoldengate, PASSWORD?AACAAAAAAAAAAGAIFAAAUDVHCFUGFIYF, ENCRYPTKEY default
SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")
SQLEXEC "ALTER SESSION SET CONSTRAINTS=DEFERRED"
?---打開數(shù)據(jù)庫中的延遲約束的特性,避免復(fù)制進程因拆分造成插入相關(guān)的約束錯誤
REPORT AT 01:59 ?---每天01:59定期生成一個report文件
REPORTCOUNT EVERY 25 MINUTES, RATE ?
---此參數(shù)每隔30分鐘,goldengate向日志文件生成一條記錄(抽取進程自從啟動后處理的記錄數(shù)與計算處理速率的信息)
REPORTROLLOVER AT 02:00 ? ---
REPERROR DEFAULT, ABEND
?---goldengate遇錯的處理原則,即遇到不能處理的錯誤就自動abend,啟動需要人工干預(yù)處理
ALLOWNOOPUPDATES ? ---當源表有排除列情況或者有目標表不存在的列時,當更新這列g(shù)oldengate默認報錯。應(yīng)用該參數(shù)后,即可讓goldengate生成一條警告信息而不是報錯
ASSUMETARGETDEFS ? ---
DISCARDFILE ./dirrpt/ya.dsc, APPEND, MEGABYTES 256M ? ---該參數(shù)的路徑必須為相對路徑,建議該參數(shù)的值設(shè)置為1024M
DISCARDROLLOVER AT 02:00 ? ---表示discard文件每天02:00定期輪轉(zhuǎn)
assumetargetdefs ? ---表示源庫與目標庫表結(jié)構(gòu)一致
ALLOWNOOPUPDATES ? ---
--DDL參數(shù)區(qū)域 需要屏蔽的操作類型在此區(qū)域屏蔽
DDL include mapped ?---DDL所有操作
ddloptions report
DDLERROR <error1> IGNORE ?--DDL?錯誤過濾
MAP??schema.,???TARGET???schema.;
修改進程啟動的隊列文件及rba號
alter <進程名> extseqno <隊列文件>,extrba 0
start <進程名>,aftercsn ? scn號
start??<進程名>
GGSCI (oracle2) 3> start replicat mrpxixi
Sending START request to MANAGER ...
REPLICAT MRPXIXI starting
GGSCI (oracle2) 4> info replicat mrpxixi
REPLICAT MRPXIXI Last Started 2018-04-13 02:03 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:09 ago)
Log Read Checkpoint File ./dirdat/md000000
First Record RBA 0
Insert,delete,update測試都沒有問題
ddl暫時還不支持,下面我們來弄ddl。
關(guān)閉回收站功能(DDL)必須關(guān)閉
SQL> show parameter recyclebin
NAME TYPE VALUE
recyclebin string on
alter system set recyclebin=off scope=spfile;這樣就需要重啟數(shù)據(jù)庫生效
SQL> @marker_setup
Marker setup script
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
Enter Oracle GoldenGate schema name:ogg
Marker setup table script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to OGG
OK
OK
Script complete.
SQL> @ddl_setup 用戶ogg最后出現(xiàn)如下
SUCCESSFUL installation of DDL Replication software components
如果報錯需要執(zhí)行@marker_remove.sql和@ddl_remove.sql腳本進行
SQL> @role_setup
SQL> grant GGS_GGSUSER_ROLE to ogg;
Grant succeeded.
SQL> @ddl_enable
Trigger altered.
OK
SQL> @?/rdbms/admin/dbmspool 該包是為了防止下面的腳本報錯才跑的。
Package created.
Grant succeeded.
SQL> @ddl_pin.sql ogg
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
GGSCI (oracle1) 18> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING CAPLQH 00:00:00 00:00:08
EXTRACT RUNNING PUMPLQH 00:00:00 39:34:33
GGSCI (oracle1) 19> stop EXTRACT CAPLQH
Sending STOP request to EXTRACT CAPLQH ...
Request processed.
GGSCI (oracle1) 20> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED CAPLQH 00:00:00 00:00:04
EXTRACT RUNNING PUMPLQH 00:00:00 00:00:08
GGSCI (oracle1) 21> edit params caplqh
內(nèi)容如下,藍色是新添加的DDL內(nèi)容
--capture change from oracle1 to oracle2
dynamicresolution
EXTRACT caplqh
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
USERID ogg, PASSWORD ogg
TRANLOGOPTIONS EXCLUDEUSER ogg
EXTTRAIL ./dirdat/qh
DDL INCLUDE ALL
ddloptions addtrandata, report
TABLE lqh.test200;
GGSCI (oracle1) 23> start EXTRACT CAPLQH
Sending START request to MANAGER ...
EXTRACT CAPLQH starting
GGSCI (oracle1) 26> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING CAPLQH 00:00:00 00:00:10
EXTRACT RUNNING PUMPLQH 00:00:00 00:00:00
修改目標端的replicat 文件
GGSCI (oracle2) 10> edit params mrpxixi
內(nèi)容如下,藍色為添加部分
REPLICAT mrpxixi
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
ASSUMETARGETDEFS
HANDLECOLLISIONS
USERID ogg PASSWORD ogg
DISCARDFILE ./dirrpt/mrpxixi.dsc,PURGE
dynamicresolution
ddloptions report
DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 3 RETRYDELAY 5
DDLERROR DEFAULT DISCARD
DDLERROR DEFAULT IGNORE RETRYOP
MAP lqh.test200, TARGET lqh.test200;
GGSCI (oracle2) 13> stop REPLICAT MRPXIXI
REPLICAT MRPXIXI is already stopped.
如果關(guān)不掉直接kill 如kill mrpxixi
GGSCI (oracle2) 14> start REPLICAT MRPXIXI
Sending START request to MANAGER ...
REPLICAT MRPXIXI starting
GGSCI (oracle2) 18> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING MRPXIXI 00:06:25 00:00:13
GGSCI (oracle2) 22> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING MRPXIXI 00:06:25 00:06:11
測試ddl也過來了,沒有問題。
ddl同步要謹慎。ogg中ddl和dml機制是分開的,ddl同步不怎么穩(wěn)定。
執(zhí)行ddl_remove.sql??移除ddl
文章題目:OGG安裝之oracle2oracle
網(wǎng)址分享:http://jinyejixie.com/article48/jjpphp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、定制網(wǎng)站、關(guān)鍵詞優(yōu)化、面包屑導(dǎo)航、定制開發(fā)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)