一. GoldenGate 概述
GoldenGate现在是业内成熟的数据容灾与复制产品;GoldenGate是一种基于日志的结构化数据复制方式,它通过解析源数据库在线日志或归档日志获得数据的增删改变化(数据量只有日志的四分之一左右),再将这些变化应用到目标数据库,实现源数据库与目标数据库同步、双活。
二. GoldenGate 搭建
目标在linux系统下安装Oracle;利用GoldenGate 实现数据同步;可复制DML和DDL操作
环境如下:本环境目标端是源端的克隆;步骤请参考第8篇
源端 | 目标端 | |
操作系统 | linux6.5 | linux6.5 |
IP | 192.168.1.235 | 192.168.1.221 |
数据库版本 | 11.2.0.4.0 | 11.2.0.4.0 |
GoldenGate版本 | 11.2.1.0.1 | 11.2.1.0.1 |
useradd -u 1003 -g oinstall -G dba ogg passwd ogg
2.2 修改 GoldenGate 系统用户环境变量
source /home/oracle/.bash_profile # or export ORACLE_BASE=/u01/app export ORACLE_HOME=$ORACLE_BASE/oracle export ORACLE_SID=ora221 export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin/data/ogg export NLS_LANG=AMERICAN_AMERICA.UTF8 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH alias sqlplus='rlwrap sqlplus' alias ggsci='rlwrap ggsci'
mkdir -p /data/ogg chown -R ogg:oinstall /data/ogg
unzip fbo_ggs_Linux_x64_ora11g_64bit.tar.zip tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar -C /data/ogg
create tablespace tsp_ogg datafile '/data/oracle/data/ogg01.dbf' size 100M autoextend on;
create user ogg identified by ogg default tablespace tsp_ogg; grant dba to ogg; GRANT CREATE TABLE,CREATE SEQUENCE TO OGG;
alter system set log_archive_dest_1 = 'LOCATION=/data/arch' scope = spfile; shutdown immediate; startup mount alter database archivelog; alter database open;
还需要开启 force log 和 supplemental log
alter database force logging; alter database add SUPPLEMENTAL log data;
最后查询结果如下:
SQL> select NAME,OPEN_MODE,FORCE_LOGGING,SUPPLEMENTAL_LOG_DATA_MIN from v$database; NAME OPEN_MODE FOR SUPPLEME --------- -------------------- --- -------- ORA235 READ WRITE YES YES
@marker_setup.sql @ddl_setup.sql @role_setup.sql @ddl_enable.sql
在11.2.0.4.0版本;需要设置
ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;
只有commit之后的日志信息才会被Capture进程捕获,未提交的事务OGG不会捕获。
[ogg@oracle235 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 (oracle235) 1> create subdirs Creating subdirectories under current directory /data/ogg Parameter files /data/ogg/dirprm: already exists Report files /data/ogg/dirrpt: created Checkpoint files /data/ogg/dirchk: created Process status files /data/ogg/dirpcs: created SQL script files /data/ogg/dirsql: created Database definitions files /data/ogg/dirdef: created Extract data files /data/ogg/dirdat: created Temporary files /data/ogg/dirtmp: created Stdout files /data/ogg/dirout: created
GGSCI (oracle235) 2> EDIT PARAMS ./GLOBALS CHECKPOINTTABLE ogg.ggschkpt GGSCI (oracle235) 3> exit [ogg@oracle235 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 (oracle235) 1> DBLOGIN USERID ogg, PASSWORD ogg Successfully logged into database. GGSCI (oracle235) 2> ADD CHECKPOINTTABLE No checkpoint table specified, using GLOBALS specification (ogg.ggschkpt)... Successfully created checkpoint table ogg.ggschkpt.
[ogg@oracle235 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 (oracle235) 1> EDIT PARAMS MGR
输入内容如下:
PORT 7809 DYNAMICPORTLIST 7800-8000 AUTORESTART EXTRACT *, WAITMINUTES 2, RESETMINUTES 5 PURGEOLDEXTRACTS /data/ogg/dirdat, USECHECKPOINTS, MINKEEPDAYS 3
GGSCI (oracle235) 2> start mgr Manager started. GGSCI (oracle235) 3> info mgr Manager is running (IP port oracle235.7809).
GGSCI (oracle235) 1> EDIT PARAMS EORA_1 EXTRACT EORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) USERID ogg, PASSWORD ogg EXTTRAIL /data/ogg/dirdat/aa TABLE lottu.*;
在源端用 add extract 命令创建 extract 组;用add exttrail 命令创建本地 trail 文件
GGSCI (oracle235) 2> ADD EXTRACT EORA_1, TRANLOG, BEGIN NOW EXTRACT added. GGSCI (oracle235) 3> ADD EXTTRAIL /data/ogg/dirdat/aa, EXTRACT EORA_1, MEGABYTES 5 EXTTRAIL added.
启动 extract 进程;在 ggsci 中:可以使用 add, alter, cleanup, delete, info, kill命令管理extract进程
GGSCI (oracle235) 4> start extract eora_1 Sending START request to MANAGER ... EXTRACT EORA_1 starting GGSCI (oracle235) 5> info eora_1 EXTRACT EORA_1 Last Started 2018-08-23 00:52 Status RUNNING Checkpoint Lag 00:06:20 (updated 00:00:04 ago) Log Read Checkpoint Oracle Redo Logs 2018-08-23 00:46:36 Seqno 12, RBA 34652672 SCN 0.0 (0)
GGSCI (oracle235) 6> EDIT PARAMS PORA_1 EXTRACT PORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) PASSTHRU RMTHOST 192.168.1.221, MGRPORT 7809 RMTTRAIL /data/ogg/dirdat/pa TABLE lottu.*;
用 add extract 指定本地 trail 文件
GGSCI (oracle235) 7> ADD EXTRACT PORA_1, EXTTRAILSOURCE /data/ogg/dirdat/aa EXTRACT added.
用 add rmttrail 指定远程 trail 文件
GGSCI (oracle235) 8> ADD RMTTRAIL /data/ogg/dirdat/pa, EXTRACT PORA_1, MEGABYTES 5 RMTTRAIL added.
启动 pump 进程
GGSCI (oracle235) 9> START EXTRACT PORA_1 Sending START request to MANAGER ... EXTRACT PORA_1 starting GGSCI (oracle235) 11> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_1 00:00:00 00:00:07 EXTRACT RUNNING PORA_1 00:00:00 00:00:02
GGSCI (oracle221) 2> EDIT PARAMS RORA_1 REPLICAT RORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) USERID ogg, PASSWORD ogg HANDLECOLLISIONS ASSUMETARGETDEFS DISCARDFILE /data/ogg/dirrpt/RORA_aa.rpt, append MAP lottu.*, TARGET lottu.*;
在目标端使用 add replicat 添加 Replicat 进程
GGSCI (oracle221) 8> add replicat RORA_1, exttrail /data/ogg/dirdat/pa REPLICAT added.
使用 start replicat 启动 Replicat 进程
GGSCI (oracle221) 11> start REPLICAT RORA_1 Sending START request to MANAGER ... REPLICAT RORA_1 starting GGSCI (oracle221) 12> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING RORA_1 00:00:00 00:00:00
alter system set recyclebin=off scope=both;
GGSCI (oracle235) 19> view params ./GLOBALS GGSCHEMA OGG
停MGR,Extract进程;
配置Extract配置文件;在配置文件添加一下内容:
DDL INCLUDE ALL
DDLOPTIONS ADDTRANDATA,REPORT
停MGR,Replicat进程;
配置Replicat配置文件;在配置文件添加一下内容:
DDL INCLUDE MAPPED
DDLOPTIONS REPORT
配置完成;在重启各进程进行验证。