1. 程式人生 > >oracle ogg配置

oracle ogg配置

oracle ogg

http://www.dataguru.cn/thread-171156-1-1.html

GoldenGate幾個重要進程介紹:

1、Manager管理進程在兩端開啟,監控和重啟其他進程;分配數據存儲和報告錯誤及事件;

2、Extract進程從日誌中抓取並傳輸到target端事務數據;

3、Server Collector進程在target(接受)端接受數據並寫入trail文件;

4、Replicat進程讀取trail文件,並應用到traget數據庫;

5、trail文件時gg自己抓捕信息的文件,是一個OS文件,存放在./dirdat/下,以X00000命名,N順序1,2,3…此文件用完可配置參數自動刪除。


問題:

1、數據庫設置為歸檔模式

2、特別註意抽取進程、投遞進程、接受進程之間的關系

抽取進程定義文件路徑為投遞進程本地路徑add extract pump_so,exttrailsource ./dirdat/et/dd

抽取進程定義遠程文件路徑為接受進程路徑add replicat rep7,exttrail ./dirdat/dp1/sd


一、環境準備並安裝GoldenGate

1. 數據庫準備情況

1) 源服務器

IP地址:192.168.14.150

數據庫:10.2.0.5 64 bit

SID: orcl

操作系統版本:Oracle 5.4 64 bit

數據庫:10.2.0.5 64 bit

SID: slave

操作系統版本:Oracle 5.4 64 bit

2. 下載OGG軟件並解壓安裝


1) 源服務器

mkdir -p /u01/app/oracle/ogg

unzip fbo_ggs_Linux_x64_ora10g_64bit.zip

tar -xvf fbo_ggs_Linux_x64_ora10g_64bit.tar -C /u01/app/oracle/ogg/

chown -R oracleinstall /u01/app/oracle/ogg


2) 目標服務器都要配置

mkdir -p /u01/app/oracle/ogg

unzip fbo_ggs_Linux_x64_ora10g_64bit.zip

tar -xvf fbo_ggs_Linux_x64_ora10g_64bit.tar -C /u01/app/oracle/ogg/

chown -R oracle:oinstall /u01/app/oracle/ogg


3. 準備OGG環境變量

#源服務器、與目標服務器都要配置

$ vi /home/oracle/.bash_profile

增加如下一行:

export GGATE=$ORACLE_BASE/ogg

生效環境變量

source /home/oracle/.bash_profile


4. 配置日誌模式

# 源服務器,目標服務器不用配置(非雙向)

1) 查看規檔與日誌模式

select log_mode,supplemental_log_data_min,force_logging from v$database;


2) 配置為規檔模式

shutdown immediate;

startup mount;

alter database archivelog;

alter database open;

alter system set log_archive_dest_1='location=/u01/archive' scope=both;


3) 配置日誌模式(打開強制規檔與補充日誌模式)

alter database add supplemental log data;

alter database force logging;


4)查看配置結果:

SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;

LOG_MODE SUPPLEME FOR

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

ARCHIVELOG YES YES


5. 創建GoldenGate用戶帳號

1) 源服務器

conn / as sysdba;

create tablespace tbs_ogg datafile '/u01/app/oracle/oradata/target/tbs_ogg.dbf' size 10m autoextend on next 10m;

create user ogg identified by ogg default tablespace tbs_ogg temporary tablespace TEMP quota unlimited on tbs_ogg;

grant connect,resource to ogg;

grant create session,alter session 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;


2) 目標服務器

conn / as sysdba;

create tablespace tbs_ogg datafile '/u01/app/oracle/oradata/orcl/tbs_ogg.dbf' size 10m autoextend on next 10m;

create user ogg identified by ogg default tablespace tbs_ogg temporary tablespace TEMP quota unlimited on tbs_ogg;

grant connect,resource to ogg;

grant create session,alter session 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 delete any table to ogg;

grant update any table to ogg;


6. 安裝GoldenGate軟件

(1) 源服務器、與目標服務器都要配置

./ggsci

GGSCI (test) 1> create subdirs

Parameter files /u01/app/oracle/ogg/dirprm: created

Report files /u01/app/oracle/ogg/dirrpt: created

Checkpoint files /u01/app/oracle/ogg/dirchk: created

Process status files /u01/app/oracle/ogg/dirpcs: created

SQL script files /u01/app/oracle/ogg/dirsql: created

Database definitions files /u01/app/oracle/ogg/dirdef: created

Extract data files /u01/app/oracle/ogg/dirdat: created

Temporary files /u01/app/oracle/ogg/dirtmp: created

Veridata files /u01/app/oracle/ogg/dirver: created


(2) 目標服務器都要配置

./ggsci

GGSCI (slave) 1> create subdirs

Creating subdirectories under current directory /u01/app/oracle/ogg

Parameter files /u01/app/oracle/ogg/dirprm: created

Report files /u01/app/oracle/ogg/dirrpt: created

Checkpoint files /u01/app/oracle/ogg/dirchk: created

Process status files /u01/app/oracle/ogg/dirpcs: created

SQL script files /u01/app/oracle/ogg/dirsql: created

Database definitions files /u01/app/oracle/ogg/dirdef: created

Extract data files /u01/app/oracle/ogg/dirdat: created

Temporary files /u01/app/oracle/ogg/dirtmp: created

Veridata files /u01/app/oracle/ogg/dirver: created


7. 配置源、目標數據庫一致

配置源與目標數據一致性可以采用很多方法,可以采用oracle的方式來完成。本方式采用imp方式來實現初始數據表一致。

(1) 源端測試用戶:

create user hr identified by hr;

grant connect,resource,select_catalog_role to hr;

conn hr/hr;

create table t1 as select * from dba_objects;

alter table t1 add constraint prikey_t1 primary key(object_id);


(2) 目標端測試用戶:

目標服務器通過exp/imp導入過去,只導入表結構

create user hr identified by hr;

grant connect,resource,select_catalog_role to hr;

conn hr/hr;

imp hr/hr file=hr.dmp rows=n

註: 還可以通過goldengate初始化數據加載的方式來實現數據同步


二、 GoldenGate DML同步源端配置

配置思路:

1) 先配置DML同步

2) 再配置DDL同步

./ggsci

1. 源MGR進程並啟動

1) 編輯主進程組

PORT 7809

DYNAMICPORTLIST 7800-7900

AUTORESTART EXTRACT *,RETRIES 3, WAITMINUTES 5, RESETMINUTES 60

PURGEOLDEXTRACTS ./dirdat/*/*, USECHECKPOINTS, MINKEEPFILES 100

LAGREPORTMINUTES 1

LAGINFOMINUTES 1

LAGCRITICALMINUTES 1

說明:

port 指定mgr進程通信端口

dynamicportlist 表示mgr進程可以為源與目的端動態通信指定端口

autorestart extract 表示自動重啟extract進程組,每2分鐘嘗試重啟所有進程,重試5次,每5分鐘清零。

配置參數後,重啟mgr進程生效


2) 啟動主管理進程

start mgr


2. 配置Extract進程組

1) 編輯配置文件

edit params eora

extract eora

dynamicresolution

SETENV (ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1")

SETENV (ORACLE_SID="source")

SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")

UsERID ogg password ogg

exttrail ./dirdat/et/dd------------該路徑與pump進程密切相關

ddl include all

ddloptions addtrandata, report

table hr.*;

2) 添加抽取進程

add extract eora, tranlog,begin now


3) 添加本地trail文件

ADD EXTTRAIL ./dirdat/et/dd(該路徑與pump進程密切相關) EXTRACT eora, MEGABYTES 5

說明:創建本地trail文件,主extract進程負責寫這部分文件,pump負責把這部分文件傳到目標服務器端。


4) 啟動服務

start extract eora


3. 配置Pump進程組

1) 編輯配置文件

edit params pump_so

EXTRACT pump_so

PASSTHRU

DYNAMICRESOLUTION

RMTHOST 192.168.31.14 ,MGRPORT 7809

RMTTRAIL ./dirdat/dp1/sd

DISCARDFILE ./dirrpt/dp2.dsc,APPEND,MEGABYTES 5

DISCARDROLLOVER AT 6:00

REPORTROLLOVER AT 6:00

REPORTCOUNT EVERY 1 HOURS,RATE

table hr.*;

2) 添加pump進程並指明本地文件

add extract pump_so,exttrailsource ./dirdat/et/dd(特別註意抽取進程文件隊列所在位置)


3) 添加遠程trail文件

add RMTTRAIL ./dirdat/dp1/sd(特別註意參數文件rmttrail位置), EXTRACT PUMP_SO, MEGABYTES 5

說明: 指定遠程trail文件

4) 啟動pump進程

start extract pump_so


三、 GoldenGate DML同步目標端配置

1. 目標端MGR進程


1) 編輯配置文件

edit params mgr

port 7809

dynamicportlist 7800-8000

autostart er *

autorestart extract *, waitminutes 2, resetminutes 5

lagreporthours 1

laginfominutes 3

lagcriticalminutes 5

purgeoldextracts /u01/app/oracle/ogg/dirdat/rt*, usecheckpoints, minkeepdays 3


2) 啟動

start mgr


2. 添加檢查表

說明: 當我們在GLOBALS 文件裏指定了默認的checkpoint 之後,新的Replicat groups 在創建時會自動使用這個參數,不需要其他指令


1) 編輯全局配置文件

edit params ./GLOBALS

Successfully logged into database.

GGSCI (slave) 2> add checkpointtable ogg.checkpoint

Successfully created checkpoint table OGG.CHECKPOINT.


配置目標端Peplicat進程組


1) 編輯配置文件

edit params repl


REPLICAT rep1

SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1" )

SETENV (ORACLE_SID = "target")

SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")

USERID ogg, PASSWORD ogg

HANDLECOLLISIONS

ASSUMETARGETDEFS

DISCARDFILE ./dirrpt/rep1.dsc ,append ,megabytes 5

--SOURCEDEFS ./dirdef/def.def

DDL INCLUDE MAPPED , OBJTYPE 'TABLE' &

INCLUDE MAPPED OBJTYPE 'INDEX'

MAP hr.T1 ,TARGET hr.T1;


2) 添加復制進程

add replicat rep7,exttrail ./dirdat/dp1/sd(該路徑為pump進程定義的遠程路徑)


3) 啟動進程

start repl


4. 可以查看checkpoint狀態

su - oracle

sqlplus ogg/ogg


SQL> select tname from tab;

TNAME

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

CHECKPOINT TABLE

CHECKPOINT_LOX TABLE

select * from checkpoint;

註1:ogg_11.1.1.1.2只有CHECKPOINT一張表。

註2:ogg_11.2.x.x.1有CHECKPOINT,CHECKPOINT_LOX兩張表。


5. DML配置測試

1) 源端查看表的記錄數

conn hr/hr

SQL> select count(*) from t1;

2)執行DML操作後提交

SQL> delete from t1 where rownum < 200;

SQL> select count(*) from t1;

3) 目標端查看

conn hr/hr

SQL> select count(*) from t1;

說明:

到此goldengate DML單向配置已經配置完畢,通過簡單的測試示例來進行。




3) 安裝DDL對象

SQL> grant dba to ogg;

SQL> @marker_setup 說明: 均指定用戶ogg

SQL> @ddl_setup 說明: 11.1.1.2需要手動輸入 ogg,INITIALSETUP,yes

SQL> @role_setup

SQL> grant GGS_GGSUSER_ROLE to ogg;

SQL> @ddl_enable

SQL> @marker_status.sql

SQL> @?/rdbms/admin/dbmspool.sql

註1: 執行dbmspool包將在數據庫中創建DBMS_SHARED_POOL包,之後ddl_pin包需要用到

註2: 執行ddl_pin.sql通過dbms_shared_pool.keep存儲過程將DDLReplication相關對象keep在共享池中,以保證這些對象不要RELOAD,提升性能。

SQL> @ddl_pin.sql ogg


2. 修改extract進程的params文件

# 服務器源端配置

# source端修改extract進程的params文件,添加"ddl include all"參數,重啟extract進程

1) 停止eora_t1進程

GGSCI (test) 2> stop extract eora


2) 編輯配置文件

GGSCI (test) 3> edit params eora

extract eora

dynamicresolution

setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)

userid ogg,password ogg

exttrail /u01/app/oracle/ogg/dirdat/et

ddl include all

ddloptions addtrandata, report

table hr.*;

# 說明:加了兩行tranlogoption 與 ddl

3)啟動mgr,eora進程

GGSCI (test) 4> start mgr

GGSCI (test) 5> start extract eora

4) 查看eora_t1進程啟動情況

GGSCI (test) 6> info extract eora


3. 修改目標端replicat進程的params文件


# 目標服務器配置

# target端修改replicat進程的params文件,

添加"ddlerror default ignore retryop maxretries 3 retrydelay 5" 等參數,重啟replicat進程

1) 停止mgr進程

GGSCI (slave) 1> stop mgr

2) 停止repl進程

GGSCI (slave) 1> stop replicat repl

3) 編輯repl配置文件

GGSCI (slave) 1> edit params repl

GGSCI (slave) 2> view params repl

replicat repl

userid ogg, password ogg

assumetargetdefs

reperror default, discard

discardfile /u01/app/oracle/ogg/dirrpt/repl.dsc, append, megabytes 50

dynamicresolution

ddloptions report

ddlerror default ignore retryop maxretries 3 retrydelay 5

ddlerror default discard

ddlerror default ignore retryop

map hr.*, target hr.*;

註: 說明目標端不需要配置DDL include all語句,不然的話,反而會出錯。

##Error text [Error code [1031], ORA-01031: insufficient privileges

4) 啟動rora_t1進程

GGSCI (slave) 5> info replicat repl

4. 測試

在源端hr用戶創建一個表,查看目標端是否成功創建。

create table abc ( id integer , name char(10));

insert into abc values ( 1 , 'abc' );


oracle ogg配置