今天通过最简单的一个例子,给大家讲解下 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 TYPEVALUE
———————————— ——————————-
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
配置环境变量