说明:设置LD_LIBRARY_PATH,为了安装OGG所用的动态链接库。如果没有配置这个路径的话,在使用OGG执行指令./ggsci的过程中会报找不到动态链接库的错误,可以在不设置LD_LIBRARY_PATH的情形下自行尝试一下错误的复现。
[oracle@host01 ogg]$ ./ggsci
./ggsci: error while loading shared libraries: libnnz12.so: cannot open shared object file: No such file or directory
2.安装OGG
在 OGG 11 中,是直接解压缩安装文件就可以了,到了 OGG 12c 的版本,OGG 使用 OUI 来进行安装。
源端和目标端均安装,步骤一样。
[oracle@host01 work]$ unzip 121210_fbo_ggs_Linux_x64_shiphome.zip
[oracle@host01 work]$ cd fbo_ggs_Linux_x64_shiphome/Disk1/
[oracle@host01 Disk1]$ ls
install response runInstaller stage
[oracle@host01 Disk1]$ export LANG=C
[oracle@host01 Disk1]$ export DISPLAY=192.168.31.67:0.0
[oracle@host01 Disk1]$ xhost +
access control disabled, clients can connect from any host
[oracle@host01 Disk1]$ ./runInstaller
3. 验证,能正常使用,且进程MANAGER已启动。如果MANAGER未启动,执行start manager。
主机在非 GG_HOME 目录下执行,会报错,只能在 GG_HOME 下执行该命令:
[oracle@host01 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 12c on Aug 7 2014 10:21:34
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (host01.example.com) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
GGSCI (host01.example.com) 2> info manager
Manager is running (IP port host01.example.com.7809, Process ID 5510).
GGSCI (host01.example.com) 3>
在 Oracle 11g 中,安装完之后,还需要用 ggsci 执行 create subdirs 创建 OGG 的目录,到了 12c,就不
用创建了,安装完后,目录都已建好。
4. 开启归档模式、强制日志、附加日志(源端)
GoldenGate 通过抓取源端数据库重做日志进行分析,将获取的数据应用到目标端,实现数据同步。因
此,源数据库需要必须处于归档模式,并启用附加日志和强制日志。
添加附加日志来唯一标识一行记录,要在数据库级别打开最小开关。为了减少整个数据库添加附加日志,以及减少归档量。
查看 v$database 看这 3 个参数是否已开启,使用 OGG 必须是开启状态
--修改前
SYS@PROD4>select LOG_MODE, SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING from v$database;
LOG_MODE SUPPLEME FORCE_LOGGING
------------ -------- ---------------------------------------
ARCHIVELOG NO NO
SYS@PROD4>alter system set log_archive_dest_1='location=/u01/archive';
System altered.
SYS@PROD4>alter database force logging;
Database altered.
SYS@PROD4>alter database add supplemental log data;
Database altered.
SYS@PROD4>alter database add supplemental log data (primary key) columns;
Database altered.
--修改后
SYS@PROD4>select LOG_MODE, SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING from v$database;
LOG_MODE SUPPLEME FORCE_LOGGING
------------ -------- ---------------------------------------
ARCHIVELOG YES YES
--切换日志组,使附加日志开关生效。
SYS@PROD4>alter system switch logfile;
System altered.
SYS@PROD4>
解释:在正常情况下,oracle是用rowid来唯一标示一行记录的,但ogg这里不够,需要打开附加日志。
--在源和目标库上设置enable_ogg_replication初始化参数为true。
SYS@PROD4>show parameter enable_goldengate_replication
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication boolean FALSE
SYS@PROD4>alter system set enable_goldengate_replication=true;
System altered.
SYS@PROD4>show parameter enable_goldengate_replication
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication boolean TRUE
SYS@PROD4>
注意:如未设置,后续的抽取进程s_e1起不来,且日志也会提示,需要修改enable_goldengate_replication参数为ture。
2016-10-19 12:08:03 ERROR OGG-02091 Oracle GoldenGate Capture for Oracle, s_e1.prm: Operation not supported because enable_goldengate_replication is not set to true.
5.创建存放 DDL 信息的 user 并赋权
SYS@PROD4>create tablespace ogg datafile '/u01/app/oracle/oradata/PROD4/ogg01.dbf' size 200m autoextend on;
Tablespace created.
--注意,在 OGG 11g 可以使用默认的 users 等表空间,但 12C 中必须独立的表空间,否则会报错。
SYS@PROD4>create user ogg identified by ogg default tablespace ogg temporary tablespace temp;
User created.
SYS@PROD4>grant connect,resource to ogg;
Grant succeeded.
SYS@PROD4>grant execute on utl_file to ogg;
Grant succeeded.
SYS@PROD4>
/*--在早期ogg版本里,需要赋予的权限较多。在ogg 12c里,在执行后续相关脚本时,有权限赋予的一步。
grant connect,resource,create session,select any dictionary,select any table,select any transaction,alter any table,alter session,flashback any table to ogg;
grant execute on utl_file to ogg;
grant connect to ogg;
grant alter any table to ogg;
grant alter session to ogg;
grant create session to ogg;
grant flashback any table to ogg;
grant select any dictionary to ogg;
grant select any table to ogg;
grant resource to ogg;
grant select any transaction to ogg;
*/
退出所有使用 Oracle 的 session,然后使用 SYSDBA 权限的用户执行执行OGG的配置脚本。
--创建 DDL 标记表
SYS@PROD4>@marker_setup.sql
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
--将在数据库中创建捕获 DDL 语句的 Trigger 等必要组件
SYS@PROD4>@ddl_setup.sql
Oracle GoldenGate DDL Replication setup script
Verifying that current user has privileges to install DDL Replication...
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be enabled.
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
--创建 GGS_GGSUSER_ROLE 角色
SYS@PROD4>@role_setup.sql
GGS Role setup script
This script will drop and recreate the role GGS_GGSUSER_ROLE
To use a different role name, quit this script and then edit the params.sql script to change the gg_role parameter to the preferred name. (Do not run the script.)
You will be prompted for the name of a schema for the GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
Enter GoldenGate schema name:ogg
--授予给 extract group 参数中定义的 userid 用户
SYS@PROD4>grant GGS_GGSUSER_ROLE to ogg;
--启用 ddl 捕获触发器
SYS@PROD4>@ddl_enable.sql
--还有 2 个可选的脚本,用来提高 DDL 复制性能:
--创建 DBMS_SHARED_POOL 包
SYS@PROD4>@?/rdbms/admin/dbmspool.sql
SYS@PROD4>@ddl_pin.sql ogg
--通过 dbms_shared_pool.keep 存储过程将 DDLReplication 相关的对象 keep 在共享池中,以保证这些对
象不要 reload,提升性能。
执行上述的脚本,在出现输入提示的时候,输入ogg用户。
7.在 Source 和 Target 上配置 Manager.
在 将源端prod4下的hr数据初始化到目标端emrep下
[oracle@host01 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 12c on Aug 7 2014 10:21:34
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (host01.example.com) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
GGSCI (host01.example.com) 2> edit params mgr
PORT 7809
DYNAMICPORTLIST 7810-7890
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *,RETRIES 5, WAITMINUTES 3,RESETMINUTES 5
PURGEOLDEXTRACTS /u01/app/oracle/ogg/dirdat/*,usecheckpoints, minkeepdays 7
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
"dirprm/mgr.prm" 8L, 246C written
GGSCI (host01.example.com) 3>
说明:
port 指定mgr进程通信端口
dynamicportlist 表示mgr进程可以为源与目的端动态通信指定端口
autorestart extract 表示自动重启extract进程组,每2分钟尝试重启所有进程,重试5次,每5分钟清零。
配置参数后,重启mgr进程生效
GGSCI (host01.example.com) 6> stop mgr
Manager process is required by other GGS processes.
Are you sure you want to stop it (y/n)?y
Sending STOP request to MANAGER ...
Request processed.
Manager stopped.
GGSCI (host01.example.com) 7> start mgr
Manager started.
GGSCI (host01.example.com) 8> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
GGSCI (host01.example.com) 9>