Oracle GoldenGate 12.2-异构环境的单项复制(支持DDL复制)

时间:2022-02-07 22:07:10

Oracle GoldenGate 12.2-异构环境的单项复制(支持DDL复制)

1下面就为大家介绍一下新版的ogg的安装实施过程。我们采用linux+oracle11g和redhat6.5+12c的异构环境搭建,先完成单向复制再扩展为支持DDL操作。

源端:操作系统redhat6.5,数据库版本:11.2.0.4ogg版本 fbo_ggs_linux_x64_shiphome.zip

2、源端安装ogg

2.1 编辑oracle用户的.bash_profile 增加环境变量

切换root用户, find / -name .bash_profile

[root@seg24 ~]# find / -name .bash_profile

修改/home/oracle/.bash_profile 文件

[root@seg24 oracle]# cat .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

 

# User specific environment and startup programs

 

ORACLE_HOME=/mirror/oracle/app/oracle/product/11.2.0/dbhome_1

PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:/opt/dmdbms/bin

 

export PATH

GG_HOME=/mirror/ogg/install

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/dmdbms/bin:$GG_HOME:$ORACLE_HOME/lib

export LD_LIBRARY_PATH

[root@seg24 oracle]#

 

静默安装ogg

1) 创建源端GoldenGate安装目录:注意权限   -- 需要根据第一步的环境变量设置:

$ mkdir -p /mirror/ogg  --安装目录

$ mkdir -p /mirror/ogg_soft  --解压目录

$mkdir -p /mirror/oraInventory --日志目录

2) 上传GoldenGate软件并安装

GoldenGate for Oracle 12c 的压缩包122022_fbo_ggs_Linux_x64_shiphome.zip上传到源端,并解压:

$ cd /mirror/ogg_soft

$ unzip 122022_fbo_ggs_Linux_x64_shiphome.zip

3) 修改response响应参数文件:

$ cd /mirror/ogg_soft/fbo_ggs_Linux_x64_shiphome/Disk1/response

 

执行如下命令修改如下参数:根据实际情况修改路径:

 

$ vi oggcore.rsp

只修改这两个参数即可:

INSTALL_OPTION=ORA11g      

SOFTWARE_LOCATION=/mirror/ogg

 

##一定要配置,且 /mirror/oraInventory要有权限

INVENTORY_LOCATION=/mirror/oraInventory

UNIX_GROUP_NAME=dba  

 

执行runInstaller命令开始静默安装:

--linux环境执行下面语句

$ ./runInstaller -silent -nowait -responseFile /mirror/ogg_soft/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp

 

至此 ogg就算安装完成了。

 

5、创建ogg用户

5.1、源端数据库

SQL> create tablespace ogg datafile '/oracle/database/oradata/inds/ogg.dbf' size 200m;

Tablespace created.

SQL> create user ogg identified by ogg default tablespace ogg;

User created.

SQL> grant connect ,resource,unlimited tablespace to ogg;

Grant succeeded.

SQL> grant execute on utl_file to ogg;

Grant succeeded.

SQL> grant select any dictionary,select any table to ogg;

Grant succeeded.

SQL> grant alter any table to ogg;

Grant succeeded.

SQL> grant flashback any table to ogg;

Grant succeeded.

SQL> grant execute on DBMS_FLASHBACK to ogg;

Grant succeeded.

SQL> show parameter enable_goldengate

NAME TYPE VALUE

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

enable_goldengate_replication boolean FALSE

SQL>grant dba to ogg;

Grant succeeded.

 

登陆源端Oracle GoldenGate,测试并确认可以访问数据库

[oracle@seg24 ogg]$ pwd

/mirror/ogg

[oracle@seg24 ogg]$ ./ggsci

 

Oracle GoldenGate Command Interpreter for Oracle

Version 12.3.0.1.4 OGGCORE_12.3.0.1.0_PLATFORMS_180415.0359_FBO

Linux, x64, 64bit (optimized), Oracle 11g on Apr 15 2018 21:16:09

Operating system character set identified as UTF-8.

 

Copyright (C) 1995, 2018, Oracle and/or its affiliates. All rights reserved.

 

 

 

GGSCI (seg24) 1> dblogin userid ogg

Password:

Successfully logged into database.

 

GGSCI (seg24 as ogg@oradb) 2>

 

6、开启归档和附加日志

1)检查源端数据库是否为归档模式,若为非归档模式,将其改为归档模式
SQL> archive log list;

2)检查源端和目标端数据库附加补充日志是否打开

SQL> shutdown immediate

 

SQL> startup mount

 

SQL> alter database archivelog ;

 

SQL> archive log list;

 

SQL> alter system switch logfile;

 

SQL>select supplemental_log_data_min from v$database;

    1.将数据库附加日志打开

    SQL>alter database add supplemental log data;

    2.切换日志以使附加日志生效

    SQL>ALTER SYSTEM ARCHIVE LOG CURRENT;

数据库的附加日志分为3个级别:

    · 数据库级别的附加日志

    SQL>alter database add supplemental log data;

    ·用户级别附加日志(使用DDL抽取功能时要启用该级别)

    GGSCI (node01 as ogg@inds) 20>add schematrandata ogg

    ·表级别的附加日志

    GGSCI (node01 as ogg@inds) 8>add trandata ogg.s_test

7、配置源端OGG

OGG配置分为源端和目标端配置,在源端配置mgr进程、extract进程、pump进程;在目标端配置mgr进程、replicat进程
对于各个进程的作用,大家都耳熟能详了,在这里就不一一阐述了。
在以往的版本中需要创建subdirs,但在最新的版本中一下在安装ogg过程中已经创建好了。

如果再执行create命令会提示“已经存在“。这是ogg的目录结构,用于保持运行过程中生成的文件

 

GGSCI (seg24 as ogg@oradb) 3> create subdirs

 

Creating subdirectories under current directory /mirror/ogg

 

Parameter file                 /mirror/ogg/dirprm: already exists.

Report file                    /mirror/ogg/dirrpt: already exists.

Checkpoint file                /mirror/ogg/dirchk: already exists.

Process status files           /mirror/ogg/dirpcs: already exists.

SQL script files               /mirror/ogg/dirsql: already exists.

Database definitions files     /mirror/ogg/dirdef: already exists.

Extract data files             /mirror/ogg/dirdat: already exists.

Temporary files                /mirror/ogg/dirtmp: already exists.

Credential store files         /mirror/ogg/dircrd: already exists.

Masterkey wallet files         /mirror/ogg/dirwlt: already exists.

Dump files                     /mirror/ogg/dirdmp: already exists.

 

 

GGSCI (seg24 as ogg@oradb) 4>

 

7.1、配置mgr

GGSCI>edit param mgr

GGSCI (seg24 as ogg@oradb) 4> info mgr

 

Manager is running (IP port seg24.7809, Process ID 76256).

 

 

GGSCI (seg24 as ogg@oradb) 5> view params mgr

 

PORT 7809

DYNAMICPORTLIST  7810-7820

--AUTOSTART ER  *

--AUTORESTART ER *,RETRIES 5,WAITMINUTES 7, RESETMINUTES 60

PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 7

 

 

 

GGSCI (seg24 as ogg@oradb) 6>

 

#添加表级trandata

GGSCI (node01 as ogg@inds) 8>add trandata hr.employees

#添加schema级别的trandata

添加schema级别的trandata,命令与添加表级别的相同add schematrandata  SCHEMA

另外还需要设置参数enable_goldengate_replication为true

SQL> show parameter enable_goldengate_replication

NAME                                               TYPE                    VALUE

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

enable_goldengate_replication        boolean                 TRUE

如果enable_goldengate_replication为false会提示以下错误

GGSCI (node01 as ogg@inds) 20>add schematrandata scott

ERROR: Operation not supported becauseenable_goldengate_replicationis not set to true.

#在这里我们需要设置参数enable_goldengate_replication为true#

SQL> alter system set enable_goldengate_replication=true scope=both ;

GGSCI (node01 as ogg@inds) 21>add schematrandata scott

2017-01-12 10:59:07 INFO OGG-01788 SCHEMATRANDATA has been added on schema scott.

2017-01-12 10:59:07 INFO OGG-01976 SCHEMATRANDATA for scheduling columns has been added on schema scott.

当然也可以通过delete schematrandata SCHEMA取消。

7.2、添加checkpoint表

目标端配置复制进程replicat之前,需要在目标数据库中创建一个checkpoint表。这个checkpoint表是基于GoldenGate checkpoint文件的,它记录了所有GoldenGate可以恢复的checkpoint以及sequence。

尽管这个操作不是必须的,但是Oracle强烈建议使用它,因为它可以使得checkpoint包含在Replicat的事物中,保证了可以从各类失败场景中恢复。

添加的步骤为在目标机器上编辑GLOBALS文件,添加

checkpointtable ogg.checkpoint

然后在ggsci中登陆ogg,使用add checkpoint添加

GGSCI (node01 as ogg@inds) 9>edit params ./GLOBALS

GGSCI (node01 as ogg@inds) 10>view params ./GLOBALS

checkpointtable ogg.checkpoint

GGSCI (node01 as ogg@inds) 12>add checkpointtable ogg.checkpoint

Successfully created checkpoint table ogg.checkpoint.

GGSCI (node01 as ogg@inds) 13>info checkpointtable ogg.checkpoint

Checkpoint table ogg.checkpoint created 2017-01-12 10:34:26.

阐述一下GLOBALS文件,它是一个全局文件,文件中的参数对全局起作用,其中的参数有mgrservname、checkpointtable、ggschema、ddltable、markertable、outputfiletable。文件名称必须大写。

7.3、配置抽取extract进程

GGSCI (node01 as ogg@inds) 16> add extract extnd,tranlog,begin now

GGSCI (node01 as ogg@inds) 17>add exttrail ./dirdat/et,extract extnd

GGSCI (node01 as ogg@inds) 14>edit params extnd

EXTRACT extnd

setenv (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")

userid ogg,password ogg

EXTTRAIL ./dirdat/et

table ogg.s_test;

GGSCI (node01 as ogg@inds) 33> start extnd

7.4、数据传输pump进程

 

Pump进程又称为secondly extract进程。如果没有pump进程,则extract进程负责将把抽取来的数据库传递给目标端,配置pump进程还有个好处就是当网络故障时,可以把数据无差错的传递给目标端。

创建parameter pump_sos文件

GGSCI (node01 as ogg@inds) 31> add extract pump_sos,exttrailsource ./dirdat/et

add rmttrail ./dirdat/pt,extract pump_sos

 GGSCI (node01 as ogg@inds) 12> edit params pump_sos

EXTRACT pump_sos

setenv (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")

userid ogg,password ogg

rmthost 10.92.208.24,mgrport 7809

rmttrail ./dirdat/pt

table ogg.s_test;

添加params pump_sos进程到ggsci队列

GGSCI (node01 as ogg@inds) 33> start pump_sos

GGSCI (node01 as ogg@inds) 34> info all

Program Status Group Lag at Chkpt Time Since Chkpt

MANAGER RUNNING

EXTRACT RUNNING EXTND 00:00:00 00:00:05

EXTRACT RUNNING PUMP_SOS 00:00:00 00:00:07

8、配置目标端

 

添加replicat复制进程

Replicat进程运行在目标端,负责读取源端抽取进程抽取的文件,然后把文件中的变化数据应用目标端,形成数据同步

创建replicat复制进程

GGSCI (Idota as ogg@mynewdb) 12> add replicat repl,exttrail ./dirdat/pt

GGSCI (Idota as ogg@mynewdb) 12> edit params repl

replicat repl

setenv (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")

userid ogg, password ogg

ASSUMETARGETDEFS

reperror default,discard

discardfile ./dirrpt/repl.dsc,append,megabytes 512

map ogg.s_test,target ogg.t_test;

GGSCI (Idota as ogg@mynewdb) 22> start repl

GGSCI (seg24 as ogg@oradb) 10> info all

 

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

 

MANAGER     RUNNING                                           

EXTRACT     RUNNING     EXTND       00:00:00      00:00:05    

EXTRACT     RUNNING     PUMP_SOS    00:00:00      00:00:08    

REPLICAT    RUNNING     REPL        00:00:00      00:00:05    

9、DML测试验证同步

源端做DML操作

insert into s_test values (3,'wzm333');

然后我们查询目标表有没有同步,

 

SQL> Select * from t_test;

 

        ID NAME

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

         1 wzm

         2 wzm2

         3 wzm333

         4 wzm4

OGG很完美的完成基于DML操作的数据同步