今天通过最简单的一个例子,给大家讲解下 goldengate 实现两台Oracle数据库的同步。
内容如下:
1.配置数据库信息。
2.安装golden gate.
3.配置golden gate.
4.测试同步情况
首先我们看看实验环境
环境
源端是一个单实例
Oracle Enterprise 5 + ORACLE 10.2.0.4
IP :10.4.128.100
目标端是一个单实例
Oracle Enterprise 5 + ORACLE 10.2.0.4
IP :10.4.128.101
两台主机均已创建数据库,sid分别为devdb 和 emrep
配置devdb 到 emrep的数据同步
goldengate版本11.2.1.0
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;
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 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
源和目标端:
[goldengate@rac1 ~]$ mkdir /opt/gg/trails
[goldengate@rac1 ~]$ ls -l /opt/gg | grep trails
源端和目标端:
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
源端:
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库之间单向同步数据
GoldenGate单向表DML同步
Oracle GoldenGate 系列:Extract 进程的恢复原理
Oracle GoldenGate安装配置
Oracle goldengate的OGG-01004 OGG-1296错误
Oracle GoldenGate快速入门教程:基本概念和配置
搭建一个Oracle到Oracle的GoldenGate双向复制环境
更多详情见请继续阅读下一页的精彩内容: