一.安装GG 软件
1.1 OS 和 DB 版本
[root@test1 oracle]# uname -a
Linux test1 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@test1 oracle]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
--对应系统版本和数据库版本下载glodengate软件
下载 ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip(11.2.0.1)
1.2 添加环境变量
在/home/oracle/.bash_profile文件里添加如下内容:(双节点都要做)
PATH=$PATH:$HOME/bin:/u01/ogg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib:/usr/X11R6/lib/
export LD_LIBRARY_PATH_64=$ORACLE_HOME/lib
LD_LIBRARY_PATH放在ORACLE_HOME后声明,否则汇报:
ggsci: error while loading shared libraries: libnnz11.so: cannot open shared object file: No such file or directory
--开启主库归档:
SQL > alter system set log_archive_dest_1='location=/u01/app/oracle/arch1/' scope=spfile;
1.3 使用ggsci工具,创建必要的目录
[oracle@thrly2 ogg]$ ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.5 14722092 OGGCORE_11.2.1.0.5_PLATFORMS_130117.1330_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Jan 17 2013 18:52:56
Copyright (C) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
GGSCI (thrly2) 1> create subdirs
Creating subdirectories under current directory /u01/ogg
Parameter files /u01/ogg/dirprm: already exists
Report files /u01/ogg/dirrpt: created
Checkpoint files /u01/ogg/dirchk: created
Process status files /u01/ogg/dirpcs: created
SQL script files /u01/ogg/dirsql: created
Database definitions files /u01/ogg/dirdef: created
Extract data files /u01/ogg/dirdat: created
Temporary files /u01/ogg/dirtmp: created
Stdout files /u01/ogg/dirout: created
二 配置Source database
2.1 归档模式、附加日志、强制日志
SQL> archive log list;
Database log mode Archive Mode
SQL> alter database force logging;
Database altered.
SQL> alter database add supplemental log data;
Database altered.
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
2.2 创建用户ggate管理gloden gate (双节点都要做)
SQL> create tablespace tbs_ggate datafile '/u01/app/oracle/oradata/thrly1/ggate01.dbf' size 100m;
SQL> create user ggate identified by ggate default tablespace tbs_ggate temporary tablespace temp;
SQL> grant connect,resource,dba to ggate;
Grant succeeded.
SQL> grant execute on utl_file to ggate;
--创建测试用户
SQL> create user paladin identified by paladin;
User created.
SQL> grant connect,resource to paladin;
Grant succeeded.
SQL> conn paladin/paladin;
--建立emp表并插入数据
2.3 添加Source database trandata
GGSCI (thrly1) 1> dblogin userid ggate,password ggate
Successfully logged into database.
GGSCI (thrly1) 2> add trandata paladin.emp
Logging of supplemental redo data enabled for table PALADIN.EMP.
2.4 Replicat端的checkpoint表,可有可无,强烈建议安装,以备检查复制情况用。
[oracle@thrly1 ogg]$ ggsci
GGSCI (thrly1) 1> view params ./GLOBALS
checkpointtable ggate.checkpoint
[oracle@thrly1 ogg]$ ggsci
GGSCI (thrly1) 1> dblogin userid ggate,password ggate
Successfully logged into database.
GGSCI (thrly1) 2> add checkpointtable ggate.checkpoint
Successfully created checkpoint table ggate.checkpoint.
3.1 在Source 和Target 上配置Manager
GGSCI (thrly1) 3> view params mgr
PORT 7809
3.2 Source端增加抽取
GGSCI (thrly1) 5> view params ext1
extract ext1
userid ggate, password ggate
dynamicresolution
extrail /u01/ogg/dirdata/et
gettruncates
table paladin.*;
GGSCI (thrly1) 6> add extract ext1,tranlog,begin now
EXTRACT added.
GGSCI (thrly1) 7> add exttrail /u01/ogg/dirdat/et,extract ext1
EXTTRAIL added.
3.3 播发进程
GGSCI (thrly1) 5> view params pump1
extract pump1
dynamicresolution
userid ggate,password ggate
rmthost 192.168.67.152,mgrport 7809
rmttrail /u01/ogg/dirdat/rt
table paladin.*;
GGSCI (thrly1) 4> add extract pump1,exttrailsource /u01/ogg/dirdat/et
EXTRACT added.
GGSCI (thrly1) 5> add rmttrail /u01/ogg/dirdat/rt,extract pump1
RMTTRAIL added.
4.1 Replicat 队列端创建同步
GGSCI (thrly2) 16> add replicat rep1,exttrail /u01/ogg/dirdat/rt,checkpointtable ggate.checkpoint
GGSCI (thrly2) 19> view params rep1
replicat rep1
ASSUMETARGETDEFS
userid ggate,password ggate
reperror default,discard
discardfile /u01/ogg/dirdat/rep1_discard.txt,append, megabytes 10
gettruncates
map paladin.*, target paladin.*;
附emp建表语句:
CREATE TABLE EMP
(EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2) );
INSERT INTO EMP VALUES
(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
INSERT INTO EMP VALUES
(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
INSERT INTO EMP VALUES
(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
INSERT INTO EMP VALUES
(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
INSERT INTO EMP VALUES
(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
INSERT INTO EMP VALUES
(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
INSERT INTO EMP VALUES
(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
INSERT INTO EMP VALUES
(7788,'SCOTT','ANALYST',7566,to_date('9-6-1987','dd-mm-yyyy'),3000,NULL,20);
INSERT INTO EMP VALUES
(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
INSERT INTO EMP VALUES
(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
INSERT INTO EMP VALUES
(7876,'ADAMS','CLERK',7788,to_date('9-4-1983','dd-mm-yyyy'),1100,NULL,20);
INSERT INTO EMP VALUES
(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
INSERT INTO EMP VALUES
(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
INSERT INTO EMP VALUES
(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);