1.配置数据库信息
在源端数据库中打开归档模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archive1
Oldest online log sequence 180
Next log sequence to archive 181
Current log sequence 181
若处于非归档模式,则改为归档模式:
SQL>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>startup mount;
ORACLE instance started.
SQL>alter database archivelog;
Database altered.
SQL>alter database open;
Database altered.
在源端数据库中打开force logging
SQL>select force_logging from v$database;
FOR
---
NO
SQL>alter database force logging;
Database altered.
SQL>select force_logging from v$database;
FOR
---
YES
在源端数据库中打开supplemental log
SQL>select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO
SQL>alter database add supplemental log data;
Database altered.
切换日志,使更改生效
SQL> alter system switch logfile;
System altered.
SQL>select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
在源端数据库中关闭回收站
官方的说明是,由于一个已知的问题,回收站会对DDL触发器产生影响,因此需要关闭。由此可见,我们只需要在源库中关闭回收站即可。
SQL>show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string on
SQL>alter system set recyclebin off; //11g中需要添加
System altered.
SQL>show parameter recyclebin
NAME TYPE VALUE
------------------------------------ -------------------------------
recyclebin string OFF
创建goldengate数据库用户(源和目标)
注意:源和目标端都需要
[oracle@rac1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jan 9 11:56:28 2015
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 32bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create tablespace goldengate;
Tablespace created.
SQL> create user goldengate identified by goldengate default tablespace goldengate;
User created.
SQL> grant connect,resource to goldengate;
Grant succeeded.
SQL> grant execute on utl_file to goldengate;
Grant succeeded.
SQL>
抽取进程使用的数据库用户需要额外的权限,我们将这些权限也授予数据库用户goldengate(在源端数据库中执行)
SQL> exec dbms_streams_auth.grant_admin_privilege('GOLDENGATE');
PL/SQL procedure successfully completed.
SQL> grant insert on system.logmnr_restart_ckpt$ to goldengate;
Grant succeeded.
SQL> grant update on sys.streams$_capture_process to goldengate;
Grant succeeded.
SQL> grant become user to goldengate;
Grant succeeded.
SQL>
为了确保GoldenGate正常运行,特别是在目标端,赋予goldengate用户DBA权限:
SQL> grant dba to goldengate;
2.GoldenGate安装环境
解压goldengate安装文件到安装目录
安装GoldenGate软件很简单,解压即可
以goldengate用户登录
[goldengate@rac1 goldengateMedia]$ mkdir /opt/gg/goldengate
[goldengate@rac1 goldengateMedia]$ cp ggs_Linux_ora10g_.tar /opt/gg/goldengate
[goldengate@rac1 goldengateMedia]$ cd /opt/gg/goldengate
[goldengate@rac1 goldengate]$ tar -xvf ggs_Linux_ora10g.tar
配置环境变量
源端和目标端:
修改goldengate用户的环境变量配置文件(ORACLE_SID按实际情况修改)
cat>>/home/goldengate/.bashrc<<EOF
ORACLE_HOME=/opt/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
ORACLE_SID=devdb
export ORACLE_SID
GG_HOME=/opt/gg/goldengate
export GG_HOME
PATH=$ORACLE_HOME/bin:$GG_HOME:$PATH
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GG_HOME:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
EOF
应用刚刚修改的环境变量,然后进入GoldenGate安装目录,执行ldd ggsci,确定需要的库文件都能够找到。如果出现共享库文件无法找到,例如libnnz10.so => not found,检查LD_LIBRARY_PATH环境变量的设置
[goldengate@ggdb goldengate]$ source ~/.bashrc
[goldengate@ggdb goldengate]$ cd $GG_HOME
[goldengate@ggdb goldengate]$ ldd ggsci
我们可以认为ogg的安装其实就是一个解压。非常简单。
(zm备注:libnnz11.so, libclntsh.so.11.1找不到的情况,是因为ogg用户没有访问oracle用户的权限,)
第一种,添加sudo权限。
第二种:以root权限访问oracle和ogg用户,那么则需要添加全局环境变量:
配置如下:
###add LD_LIBRARY_PATH###
ORACLE_HOME=/opt/oracle/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME
ORACLE_SID=orcl
export ORACLE_SID
OGG_HOME=/opt/ogg/
export OGG_HOME
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PATH=$ORACLE_HOME/bin:$OGG_HOME:$PATH
export PATH
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$OGG_HOME:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
第三种:修改该文件的属性值为777 chmod 777 libnnz11.so libclntsh.so.11.1
(777 所有用户都可以访问, 770是同组,771 是所有用户可读,同组所有权限--linux的用户权限只是 1-read 2-write 4-exeute )
[root@localhost ogg]# source /etc/profile
[root@localhost ogg]# ldd ggsci
linux-vdso.so.1 => (0x00007fffcbfcc000)
libdl.so.2 => /lib64/libdl.so.2 (0x000000357a800000)
libgglog.so => /opt/ogg/./libgglog.so (0x00007f8be659d000)
libggrepo.so => /opt/ogg/./libggrepo.so (0x00007f8be6449000)
libdb-5.2.so => /opt/ogg/./libdb-5.2.so (0x00007f8be61a8000)
libicui18n.so.38 => /opt/ogg/./libicui18n.so.38 (0x00007f8be5e47000)
libicuuc.so.38 => /opt/ogg/./libicuuc.so.38 (0x00007f8be5b0e000)
libicudata.so.38 => /opt/ogg/./libicudata.so.38 (0x00007f8be4b32000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000357b000000)
libxerces-c.so.28 => /opt/ogg/./libxerces-c.so.28 (0x00007f8be461a000)
libantlr3c.so => /opt/ogg/./libantlr3c.so (0x00007f8be4504000)
libnnz11.so => /opt/oracle/app/oracle/product/11.2.0/dbhome_1/lib/libnnz11.so (0x00007f8be413b000)
libclntsh.so.11.1 => /opt/oracle/app/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so.11.1 (0x00007f8be1b10000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003586400000)
libm.so.6 => /lib64/libm.so.6 (0x000000357b400000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003587000000)
libc.so.6 => /lib64/libc.so.6 (0x000000357ac00000)
/lib64/ld-linux-x86-64.so.2 (0x000000357a400000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x000000358a000000)
libaio.so.1 => /lib64/libaio.so.1 (0x00007f8be190d000)
[root@localhost 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 (localhost.localdomain) 1>
3.配置goldengate
创建goldengate工作目录
源端和目标端:
[goldengate@rac1 goldengate]$ cd $GG_HOME
[goldengate@rac1 goldengate]$ ./ggsci
GGSCI (rac1) 1> create subdirs
Creating subdirectories under current directory /opt/gg/goldengate
Parameter files /opt/gg/goldengate/dirprm: created
Report files /opt/gg/goldengate/dirrpt: created
Checkpoint files /opt/gg/goldengate/dirchk: created
……
GGSCI (gg1) 2> exit
创建trail文件存放目录
源和目标端:
[goldengate@rac1 ~]$ mkdir /opt/gg/trails
[goldengate@rac1 ~]$ ls -l /opt/gg | grep trails
配置MANAGER
源端和目标端:
DYNAMICPORTLIST中配置了GoldenGate(extract和replicat)进程使用的端口范围
PORT参数指定MANAGER使用的端口
AUTORESTART参数使抽取/复制进程失败后自动重启
配置MANAGER的参数,PURGEOLDEXTRACTS参数指定:当根据checkpoint发现已经完成抽取和复制的trail文件将被自动删除,但保留最近10个。
PURGEDDLHISTORY和PURGEMARKERHISTORY分别删除DDL历史表和marker表中的过期数据,以控制它们不会变得过于庞大。
GGSCI (gg1) 1> edit params mgr
PORT 5898
PURGEOLDEXTRACTS /opt/gg/trails/w1*, USECHECKPOINTS, MINKEEPFILES 10
AUTORESTART ER *, RETRIES 3, WAITMINUTES 5
PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
当出现以下错误
[root@localhost ~]# 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 (localhost.localdomain) 1> edit params mgr
Cannot load ICU resource bundle 'ggMessage', error code 2 - No such file or directory
Cannot load ICU resource bundle 'ggMessage', error code 2 - No such file or directory
Aborted (core dumped)
解决方法;
切换到OGG用户的home目录下;
[root@localhost ~]# cd $OGG_HOME
[root@localhost 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 (localhost.localdomain) 1> edit params mgr
PORT 7809
~
全局参数设置
源端:
GGSCI (rac1) 2> edit params ./globals
GGSCHEMA goldengate
目标端:
创建一个checkpoint表
replicat通过这个表来维护trail文件中的read position。这不是个必须的操作,如果没有这个表,则通过一个磁盘文件来维护
GGSCI (ggdb) 2> dblogin userid goldengate,password goldengate
Successfully logged into database.
GGSCI (ggdb) 3> add checkpointtable goldengate.chkpoint
Successfully created checkpoint table GOLDENGATE.CHKPOINT.
GGSCI (ggdb) 4> edit params ./globals
GGSCHEMA goldengate
CHECKPOINTTABLE goldengate.chkpoint
使用OGG,两个Oracle库之间单向同步数据 请参看 http://www.linuxidc.com/Linux/2014-07/104465.htm