1.软件准备
1.1解压软件
源端目标端都要做
创建安装目录
mkdir /ogg
chown oracle:oinstall /ogg
将软件上传到ogg目录下
解压
tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar
软件目录结构:
[oracle@rac2 ogg]$ ls
bcpfmt.tpl ddl_ddl2file.sql ddl_pin.sql ddl_tracelevel.sql demo_ora_misc.sql freeBSD.txt libgglog.so marker_setup.sql replicat ulg.sql
bcrypt.txt ddl_disable.sql ddl_purgeRecyclebin.sql ddl_trace_off.sql demo_ora_pk_befores_create.sql ggcmd libggrepo.so marker_status.sql retrace UserExitExamples
cfg ddl_enable.sql ddl_remove.sql ddl_trace_on.sql demo_ora_pk_befores_insert.sql ggMessage.dat libicudata.so.38 mgr reverse usrdecs.h
chkpt_ora_create.sql ddl_filter.sql ddl_session1.sql defgen demo_ora_pk_befores_updates.sql ggsci libicui18n.so.38 notices.txt role_setup.sql zlib.txt
cobgen ddl_nopurgeRecyclebin.sql ddl_session.sql demo_more_ora_create.sql dirjar help.txt libicuuc.so.38 oggerr sequence.sql
convchk ddl_ora10.sql ddl_setup.sql demo_more_ora_insert.sql dirprm jagent.sh libxerces-c.so.28 params.sql server
db2cntl.tpl ddl_ora10upCommon.sql ddl_status.sql demo_ora_create.sql emsclnt keygen libxml2.txt prvtclkm.plb sqlldr.tpl
ddl_cleartrace.sql ddl_ora11.sql ddl_staymetadata_off.sql demo_ora_insert.sql extract libantlr3c.so logdump pw_agent_util.sh tcperrs
ddlcob ddl_ora9.sql ddl_staymetadata_on.sql demo_ora_lob_create.sql fbo_ggs_Linux_x64_ora11g_64bit.tar libdb-5.2.so marker_remove.sql remove_seq.sql ucharset.h
1.2修改环境变量
源端目标端都要做
vi /home/oracle/.bash_profile
添加:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
1.3检查安装
源端目标端都要做
[oracle@ogg ogg]$ ldd ggsci
linux-vdso.so.1 => (0x00007fff92f6a000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f469672b000)
libgglog.so => /ogg/./libgglog.so (0x00007f46964f5000)
libggrepo.so => /ogg/./libggrepo.so (0x00007f46963a1000)
libdb-5.2.so => /ogg/./libdb-5.2.so (0x00007f4696100000)
libicui18n.so.38 => /ogg/./libicui18n.so.38 (0x00007f4695d9f000)
libicuuc.so.38 => /ogg/./libicuuc.so.38 (0x00007f4695a66000)
libicudata.so.38 => /ogg/./libicudata.so.38 (0x00007f4694a8a000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f469486d000)
libxerces-c.so.28 => /ogg/./libxerces-c.so.28 (0x00007f4694356000)
libantlr3c.so => /ogg/./libantlr3c.so (0x00007f4694240000)
libnnz11.so => /u01/app/oracle/product/11.2.0/db_1/lib/libnnz11.so (0x00007f4693e72000)
libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0/db_1/lib/libclntsh.so.11.1 (0x00007f4691408000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f4691101000)
libm.so.6 => /lib64/libm.so.6 (0x00007f4690dfe000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4690be8000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4690827000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4696937000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f469060d000)
libaio.so.1 => /lib64/libaio.so.1 (0x00007f469040b000)
以上结果没出现not found,说明安装成功
出现not found情况:
执行ggsci不能正常进入goldengate软件
[oracle@ogg ogg]$ ./ggsci
./ggsci: error while loading shared libraries: libnnz11.so: cannot open shared object file: No such file or directory
查看数据库是否有所需文件
[oracle@ogg ogg]$ cd $ORACLE_HOME/lib
[oracle@ogg lib]$ ls -l libnnz11.so
-rw-r--r-- 1 oracle oinstall 7996693 Jul 9 2013 libnnz11.so
[oracle@ogg lib]$ ls -l libclntsh.so.11.1
-rwxr-xr-x 1 oracle oinstall 53793682 Jun 15 05:50 libclntsh.so.11.1
将数据库文件软连接到goldengate目录下
[oracle@ogg lib]$ ln -s $ORACLE_HOME/lib/libnnz11.so /u01/ogg_soft/./libnnz11.so
[oracle@ogg lib]$ ln -s $ORACLE_HOME/lib/libclntsh.so.11.1 /u01/ogg_soft/./libclntsh.so.11.
oracle@ogg ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.32 21609058 OGGCORE_11.2.1.0.0OGGBP_PLATFORMS_151212.0607_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Feb 7 2016 21:54:48
Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
GGSCI (ogg) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
GGSCI (ogg1) 2>
能正常登录,表示安装成功
至此软件安装完成
2.基础环境准备
2.1创建子目录
源端目标端都要做
GGSCI (ogg) 2> create subdirs
Creating subdirectories under current directory /ogg
Parameter files /ogg/dirprm: already exists
Report files /ogg/dirrpt: created
Checkpoint files /ogg/dirchk: created
Process status files /ogg/dirpcs: created
SQL script files /ogg/dirsql: created
Database definitions files /ogg/dirdef: created
Extract data files /ogg/dirdat: created
Temporary files /ogg/dirtmp: created
Stdout files /ogg/dirout: created
2.2开启归档
源端上操作
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 50
Next log sequence to archive 52
Current log sequence 52
若为非归档模式,则调整为归档模式(需要停库,谨慎操作)
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
2.3修改goldengate参数
源端上操作
SQL> show parameter enable_goldengate_replication
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
enable_goldengate_replication boolean FALSE
SQL> alter system set enable_goldengate_replication=true scope=both;
System altered.
SQL> show parameter enable_goldengate_replication
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
enable_goldengate_replication boolean TRUE
开启了该参数才能使用goldengate
2.3设置强制日志模式
源端上操作
SQL> select force_logging from v$database;
FORCE_
------
NO
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_
------
YES
2.4开启附加日志
源端上操作
SQL> select supplemental_log_data_min from v$database;
SUPPLEMENTAL_LOG
----------------
NO
SQL> alter database add supplemental log data;
Database altered.
SQL> select supplemental_log_data_min from v$database;
SUPPLEMENTAL_LOG
----------------
YES
2.5关闭数据库回收站
源端上操作,该步骤可以不做
回收站根据需求可不关闭。如果数据库是10g,需要关闭recyclebin并重启或者手工purge recyclebin。
SQL> show parameter recyclebin
NAME TYPE VALUE
--------------- ---------------------- ------------------------------
recyclebin string on
SQL> alter system set recyclebin=off scope=spfile;
System altered.
SQL> show parameter recyclebin
NAME TYPE VALUE
--------------- ---------------------- ------------------------------
recyclebin string off
2.6创建ogg用户和表
源端目标端都要做
创建ogg的表空间
因为源端是asm便用+DATA
SQL> create tablespace ggate datafile '+DATA/dave/datafile/oggate01.dbf' size 10m autoextend on;
目标端
SQL> create tablespace ggate datafile '/u01/app/oracle/oradata/orcl/oggate01.dbf' size 10m autoextend on;
上产上一般给几G的表空间,不开启自动增涨
创建oggate用户
SQL> create user oggate identified by "123456" default tablespace ggate;
SQL> grant resource,connect,dba to oggate;
虽然goldengate不全使用到dba权限,但不要严格要求就设置dba权限
创建表
CREATE TABLE oggtable(id number);
alter table oggtable add name varchar(30)
insert into oggtable(id,name) values(1,'aaa');
insert into oggtable(id,name) values(2,'bbb');
insert into oggtable(id,name) values(3,'ccc');
insert into oggtable(id,name) values(4,'bbb');
3.配置进程
3.1编辑GLOBALS参数文件
源端目标端都要做
GGSCHEMA oggate:指定的进行复制的数据库用户
CHECKPOINTTABLE oggate.checkpoint:ogg用户的checkpoint表,定位中断的位置,下次启动从中断的位置开始恢复。
源库:
GGSCHEMA oggate
目标库:
GGSCHEMA oggate
CHECKPOINTTABLE oggate.checkpointtable
步骤:
源端下添加:
GGSCI (rac2) 4> EDIT PARAMS ./GLOBALS
GGSCHEMA oggate
目标端下添加:
GGSCI (rac2) 4> EDIT PARAMS ./GLOBALS
GGSCHEMA oggate
CHECKPOINTTABLE oggate.checkpoint
3.2添加附加日志
源端:
dblogin Userid oggate,PASSWORD 123456
add trandata oggate.oggtable
INFO trandata oggate.oggtest
目标端:
dblogin userid oggate,password 123456
add checkpointtable oggate.checkpointtable
详细步骤:
源端:
GGSCI (rac2) 43> dblogin Userid oggate,PASSWORD 123456
Successfully logged into database.
GGSCI (rac2) 44> add trandata oggate.oggtable
2021-04-30 00:35:22 WARNING OGG-00869 No unique key is defined for table 'OGGTABLE'. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo data enabled for table OGGATE.OGGTABLE.
此处有WARNING是因为上面创建的表没有主机主键或唯一主键,生产上的表都要有逐渐,因为只是测试没事
GGSCI (rac2) 83> info trandata oggate.oggtable
Logging of supplemental redo log data is enabled for table OGGATE.OGGTABLE.
Columns supplementally logged for table OGGATE.OGGTABLE: ID, NAME.
目标端:
GGSCI (ogg) 6> dblogin userid oggate,password 123456
Successfully logged into database.
GGSCI (ogg) 7> add checkpointtable oggate.checkpointtable
Successfully created checkpoint table oggate.checkpointtable.
3.3生成密文
GGSCI (rac2) 8> ENCRYPT PASSWORD 123456 BLOWFISH ENCRYPTKEY DEFAULT
Using default key...
Encrypted password: AACAAAAAAAAAAAGARGMHZCVCDBREOBNH
Algorithm used: BLOWFISH
3.4配置MGR管理进程
源端目标端都要做
GGSCI (rac2) 7> edit params mgr
port 7809
DYNAMICPORTLIST 7810-7900
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
配置完成后全都启动起来
GGSCI (rac2) 8> start mgr
GGSCI (ogg) 2> start mgr
3.5配置EXTRACT抽取进程
源端
添加抽取进程
add extract E_CQ, tranlog, begin now, threads 2
添加抽取进程的队列文件
add exttrail ./dirdat/cp, extract E_CQ, megabytes 100
此处的threads 2是根据redo日志组来决定的;megabytes 100是队列文件大小为100M
源端:
SQL> select MEMBERS from v$log;
MEMBERS
----------
2
2
2
2
详细步骤:
GGSCI (rac2) 6> edit params E_CQ
EXTRACT E_CQ
SETENV (ORACLE_SID="dave2")
SETENV (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
USERID oggate, PASSWORD AACAAAAAAAAAAAGARGMHZCVCDBREOBNH, BLOWFISH, ENCRYPTKEY DEFAULT
REPORTCOUNT EVERY 1 MINUTES, RATE
DISCARDFILE ./dirrpt/cq.dsc,APPEND,MEGABYTES 1024
DBOPTIONS ALLOWUNUSEDCOLUMN
WARNLONGTRANS 2h,CHECKINTERVAL 3m
EXTTRAIL ./dirdat/cq
FETCHOPTIONS NOUSESNAPSHOT
TRANLOGOPTIONS DBLOGREADER
TABLE oggate.oggtable;
GGSCI (rac2) 4> add extract E_CQ, tranlog, begin now, threads 2
GGSCI (rac2) 5> add exttrail ./dirdat/cq, extract E_CQ, megabytes 100
3.6配置PUMP投递进程
源端
edit params P_TD
add extract P_TD, exttrailsource ./dirdat/cq, begin now
详细步骤:
GGSCI (rac2) 21> edit params P_TD
extract P_TD
SETENV (ORACLE_SID="dave2")
SETENV (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
USERID oggate, PASSWORD AACAAAAAAAAAAAGARGMHZCVCDBREOBNH, BLOWFISH, ENCRYPTKEY DEFAULT
REPORT AT 01:59
REPORTROLLOVER AT 02:00
CACHEMGR, CACHESIZE 256MB
FLUSHCSECS 30
NUMFILES 3000
EOFDELAYCSECS 30
RMTHOST 192.168.100.50,MGRPORT 7809, TCPBUFSIZE 100000, TCPFLUSHBYTES 300000
RMTTRAIL ./dirdat/cq
PASSTHRU
DYNAMICRESOLUTION
GETUPDATEBEFORES
NOCOMPRESSDELETES
TABLE oggate.oggtable;
GGSCI (rac2) 22> add extract P_TD, exttrailsource ./dirdat/cq, begin now
GGSCI (rac2) 23> add rmttrail ./dirdat/cq, extract P_TD, megabytes 200
3.7初始化数据
源端目标端都要做
创建数据泵目录
mkdir /home/oracle/dmp
create directory tmp_exp as '/home/oracle/dmp';
grant read,write on directory tmp_exp to oggate;
源库查找scn号
select current_scn from v$database;
详细步骤:
源端:
[oracle@rac2 ~]$ mkdir /home/oracle/dmp
[oracle@rac2 ~]$ ll
total 0
drwxr-xr-x 2 oracle oinstall 6 Apr 30 02:11 dmp
SQL> create directory tmp_exp as '/home/oracle/dmp';
SQL> grant read,write on directory tmp_exp to oggate;
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
1100723
[oracle@rac2 dmp]$ expdp oggate/123456 directory=tmp_exp dumpfile=oggtest.dmp logfile=oggtest.log tables=oggate.oggtable FLASHBACK_SCN=1100723
将备份出来的备份集传到目标端
[oracle@rac2 dmp]$ scp oggtest.dmp oracle@192.168.100.50:/home/oracle/dmp
目标端:
[oracle@ogg dmp]$ impdp oggate/123456 directory=tmp_exp dumpfile=oggtest.dmp logfile=oggtest.log tables=oggate.oggtable TABLE_EXISTS_ACTION=REPLACE
3.8配置复制进程
edit params R_FZ
add replicat R_FZ, exttrail ./dirdat/cq, checkpointtable oggate.checkpointtable
详细步骤:
GGSCI (ogg) 3> edit params R_FZ
replicat R_FZ
SETENV (ORACLE_SID="orcl")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
Userid oggate,PASSWORD AACAAAAAAAAAAAGARGMHZCVCDBREOBNH, BLOWFISH, ENCRYPTKEY DEFAULT
REPORT AT 01:59
REPORTROLLOVER AT 02:00
CACHEMGR, CACHESIZE 256MB
REPERROR DEFAULT,ABEND
DISCARDFILE ./dirrpt/R_FZ.dsc,APPEND,MEGABYTES 100
DISCARDROLLOVER AT 06:00
GETTRUNCATES
NUMFILES 3000
EOFDELAYCSECS 30
ASSUMETARGETDEFS
ALLOWNOOPUPDATES
DYNAMICRESOLUTION
GETUPDATEBEFORES
NOCOMPRESSDELETES
MAP oggate.oggtable, TARGET oggate.oggtable;
GGSCI (ogg) 4> add replicat R_FZ, exttrail ./dirdat/cq, checkpointtable oggate.checkpointtable
REPLICAT added.
GGSCI (ogg) 5> start R_FZ
Sending START request to MANAGER ...
REPLICAT R_FZ starting
4.测试
4.1insert操作
源端:
select * from oggtable
3 ccc
4 ddd
1 aaa
2 bbb
insert into oggtable(id,name) values(5,'eee');
select * from oggtable
3 ccc
4 ddd
5 eee
1 aaa
2 bbb
目标端:
select * from oggtable
3 ccc
4 ddd
5 eee
1 aaa
2 bbb
4.2update操作
源端:
select * from oggtable
3 ccc
4 ddd
5 eee
1 aaa
2 bbb
update oggtable set name='e1e1' where id=5;
select * from oggtable
3 ccc
4 ddd
5 e1e1
1 aaa
2 bbb
目标端:
select * from oggtable
3 ccc
4 ddd
5 e1e1
1 aaa
2 bbb
4.3delete操作
源端:
select * from oggtable
3 ccc
4 ddd
5 e1e1
1 aaa
2 bbb
delete oggtable where id=1;
select * from oggtable
3 ccc
4 ddd
5 e1e1
2 bbb
目标端:
select * from oggtable
3 ccc
4 ddd
5 e1e1
2 bbb