二Goldengate的配置
此处配置使用GG的架构是: Extract+Data Pump + Replicat
1、在源端操作系统上设置该用户环境变量(建议采用oracle的安装用户安装运行GoldenGate).
在/home/oracle/.bash_profile文件里添加如下内容:
Export PATH=/ggs:${PATH}:/u01/app/common/oracle/bin
Export LD_LIBRARY_PATH=/ggs:$LD_LIBRARY_PATHI:/lib:/usr/lib:/usr/local/lib
加载刚刚设置的环境变量:
[oracle@oratest ~]$source .bash_profile
2 、将goldengate安装介质FTP上转到服务器,用zip/tar命令解包.
[oracle@oratest ~]$ mkdir /ggs
[oracle@oratest ggs]$ unzip fbo_ggs_Linux_x64_ora11g_64bit.zip
Archive: fbo_ggs_Linux_x64_ora11g_64bit.zip
inflating:fbo_ggs_Linux_x64_ora11g_64bit.tar
inflating:OGG_WinUnix_Rel_Notes_11.1.1.1.2.pdf
inflating:Oracle_GoldenGate_11.1.1.1_README.txt
[oracle@oratest ggs]$ tar xvffbo_ggs_Linux_x64_ora11g_64bit.tar
3 、在数据库中创建GoldenGate数据库用户,名称无所谓,这里以goldengate为例,用户至少应该有connect,resource,selectany dictionary,select any table的权限,当然如果能给dba,一切就都覆盖了:
在源端创建用户:
SQL> conn /as sysdba
Connected.
SQL> createuser goldengate identified by goldengate;
User created.
SQL> grant dbato goldengate;
Grant succeeded
在源端和目标端创建用户
C:\Users\Administrator>sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on星期三 2月 2216:58:21 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> conn /as sysdba
已连接。
SQL> create user goldengate identified by goldengate;
用户已创建。
SQL> grant dbato goldengate;
授权成功。
su- oracle
cd /ggs
[oracle@oratest ggs]$./ggsci
Oracle GoldenGateCommand Interpreter for Oracle
Version 11.1.1.1.2OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
Linux, x64, 64bit(optimized), Oracle 11g on Oct 4 201123:49:46
Copyright (C) 1995,2011, Oracle and/or its affiliates. All rights reserved.
GGSCI (w-krjx33mp4glzk) 18> dblogin userid goldengatepassword goldengate
Successfully logged into database.
GGSCI (w-krjx33mp4glzk) 19> create subdirs
Creating subdirectories under current directory D:\ggs
Parameter files D:\ggs\dirprm: created
Report files D:\ggs\dirrpt: created
Checkpoint files D:\ggs\dirchk: created
Process status files D:\ggs\dirpcs: created
SQL script files D:\ggs\dirsql: created
Database definitions files D:\ggs\dirdef: created
Extract data files D:\ggs\dirdat: created
Temporary files D:\ggs\dirtmp: created
Veridata files D:\ggs\dirver: created
Veridata Lock files D:\ggs\dirver\lock: created
Veridata Out-Of-Sync files D:\ggs\dirver\oos: created
Veridata Out-Of-Sync XML files D:\ggs\dirver\oosxml:created
Veridata Parameter files D:\ggs\dirver\params: created
Veridata Report files D:\ggs\dirver\report: created
Veridata Status files D:\ggs\dirver\status: created
Veridata Trace files D:\ggs\dirver\trace: created
Stdout files D:\ggs\dirout: created
目录说明
Dirrpt,是存放日志的目录
Dirrpm,是存放进程配置文件的目录
Dirdat,是存放trail文件的目录
Dirchk,是存放检查点文件的目录
4 、检查源端数据库是否为归档模式,若为非归档模式,建议将其改为归档模式,打开附加日志:
源端开始归档附加日志,目标端不用开启归档和附加日志
SQL> archivelog list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 9
Current log sequence 11
SQL> shutimmediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startupmount
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 1023412216 bytes
Database Buffers 620756992 bytes
Redo Buffers 7135232 bytes
Database mounted.
SQL> alterdatabase archivelog;
Database altered.
SQL> altersystem set log_archive_dest_1='location=/arch';
System altered.
SQL> alterdatabase open;
Database altered.
SQL> archivelog list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch
Oldest online log sequence 9
Next log sequence to archive 11
Current log sequence 11
SQL> exit
Disconnected from Oracle Database 11g Enterprise EditionRelease 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and RealApplication Testing options
[oracle@oratest ~]$ cd /
[root@oratest /]#mkdir /arch
[root@oratest /]# chown oracle:dba /arch
[root@oratest /]# ll
drwxr-xr-x 2oracle dba 4096 Feb 22 14:06 arch
SQL> selectsupplemental_log_data_min from v$database;
SUPPLEMENTAL_LOG
----------------
NO
SQL>alter database add supplemental log data;
Databasealtered.
SQL>alter system archive log current;
Systemaltered.
5、goldengate的配置
在进行goldengate的配置之前,我们还需要对数据库进行一些操作,当然,这些操作也可以拿到后面进行,但必须在extract进程启动之前进行。
ggsci>dblogin userid <username>, password<password>
这里username是登录数据库的用户,它不一定是刚才我们为goldengate建立的数据库用户,但它必须有dba权限,password是数据库登录的密码,登录后运行:
6.1在源端和目标端配置并启动mgr管理进程
源端:
GGSCI(oratest) 5>edit params mgr
加入一行port 7809,端口号可以随意设置,只要不冲突,有权限即可
存盘退出,然后运行start mgr,并检查manager进程的状态:
GGSCI(oratest) 6> start mgr
Managerstarted.
GGSCI(oratest) 7> info mgr
Manageris running (IP port oratest.7809).
在目标端:
GGSCI(WIN-AKOOCCILK8T) 9>edit params mgr
port7809
GGSCI(WIN-AKOOCCILK8T) 11>start mgr
在源和目标上做同样的操作,务必保证源和目标的manager进程正常运行,否则后面的配置会出现错误。至此goldengate manager管理进程配置完毕.
6.2在提示符下运行dblogin登陆
GGSCI (oratest) 4>dblogin userid goldengate, password goldengate
Successfully logged into database.
6.3添加所要同步的表
GGSCI (oratest) 6>add trandata scott.t1
这里schema_name和t1是goldengate要同步的所有表,也就是说针对每一张表,都要做一遍,当然你可以采用add trandata <schema_name>.*,或者采用sqlplus中的select fromdba_tables批量生成脚本。
6.3源端增加抽取进程
GGSCI (oratest) 14>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
GGSCI (oratest) 15>add extract exta_1,tranlog,threads 1,begin now
EXTRACT added.
GGSCI (oratest) 16>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED EXTA_1 00:00:00 00:00:04
GGSCI (oratest) 17>edit params exta_1
输入:
extract exta_1
userid goldengate,password goldengate
exttrail /ggs/dirdat/aa #trail文件,dirdat目录下以aa为前缀(aa000001)
rmthost 10.10.8.54,mgrport 7809
table scott.*;
GGSCI (oratest) 18> add exttrail /ggs/dirdat/aa,extractexta_1
EXTTRAIL added.
GGSCI (oratest) 19> add extract dpa_1 exttrailsource /ggs/dirdat/aa
EXTRACT added.
GGSCI (oratest) 20> add rmttrail F:\ggs_window\dirdat\aa,extract dpa_1
RMTTRAIL added.
GGSCI (oratest) 21>edit params dpa_1
输入:
extract dpa_1
passthru --不检查表的定义
rmthost 10.10.8.54,mgrport 7809
rmttrail F:\ggs_window\dirdat\aa #传输到目标端的trail文件
table scott.*;
GGSCI (oratest) 23>start exta_1
Sending START request to MANAGER ...
EXTRACT EXTA_1 starting
GGSCI (oratest) 24>start dpa_1
Sending START request to MANAGER ...
EXTRACT DPA_1 starting
GGSCI (oratest) 25>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DPA_1 00:00:00 00:00:03
EXTRACT RUNNING EXTA_1 00:00:00 00:00:02
目标端的配置:+
GGSCI (WIN-AKOOCCILK8T) 27>add replicat repa_1,exttrail /ggs/dirdat/aa, nodbcheckpoint
REPLICAT added.
GGSCI (WIN-AKOOCCILK8T) 13> edit params repa_1
输入:
replicat repa_1
assumetargetdefs
userid goldengate,password goldengate
map scott.T1, target scott.T1;
GGSCI (WIN-AKOOCCILK8T) 28>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
REPLICAT STOPPED REPA_1 00:00:00 00:00:03
GGSCI (WIN-AKOOCCILK8T) 29> start repa_1
Sending START request to MANAGER ...
REPLICAT REPA_1 starting
GGSCI (WIN-AKOOCCILK8T) 30>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REPA_1 00:00:00 00:00:08
GGSCI (oratest) 4>dblogin useridgoldengate,password goldengate
Successfully logged into database.
GGSCI (oratest) 5>add trandata scott.*
到此,goldengate配置完成。
测试:
实验一:在源端和目标端各有一个t1表,唯一索引列建在deptno,通过在源端插入数据,测试源端的数据可以同步到目标端上:
Create table t1 as select * from deptwhere 0=1;
Creae index i1 on t1(deptno);
如果一个表没有主键或者唯一索引或用整行作为唯一标准符,来传输数据变动的目标端
在源端查看进程的信息:
GGSCI (oratest) 23>send exta_1status
Sending STATUS request to EXTRACT EXTA_1 ...
EXTRACT EXTA_1 (PID 19061)
Current status:Recovery complete: At EOF
Current readposition:
Redo thread #: 1
Sequence #: 126
RBA: 11731456
Timestamp:2012-03-12 14:04:35.000000
SCN: 0.3917852
Current writeposition:
Sequence #: 12
RBA: 1018
Timestamp:2012-03-12 14:04:35.944779
Extract Trail:/ggs/dirdat/aa
GGSCI (oratest) 24>send dpa_1 status
Sending STATUS request to EXTRACT DPA_1 ...
EXTRACT DPA_1 (PID 19071)
Current status:Recovery complete: At EOF
Current readposition:
Sequence#: 12
RBA: 1018
Timestamp:2012-03-12 14:00:41.644157
Extract Trail:/ggs/dirdat/aa
Current writeposition:
Sequence #: 10
RBA: 1333
Timestamp:2012-03-12 14:04:55.284858
Extract Trail:F:\ggs_window\dirdat\aa
目标端进程的信息:
GGSCI (WIN-AKOOCCILK8T) 15>send repa_1 status
Sending STATUS request to REPLICAT REPA_1 ...
Current status:At EOF
Sequence #: 10
RBA: 1333
0 records incurrent transaction
目标端:查看t1表示空的,;
SQL> select * from t1;
未选定行
在源端:
SQL> insert into t1 select * from dept;
4 rows created.
SQL> commit;
Commit complete.
目标端查看:
SQL> select * from t1;
未选定行
SQL> select * from t1;
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
说明数据已经同步到目标端.
在查看源端进程信息:
GGSCI (oratest) 3>send exta_1 status
Sending STATUS request to EXTRACT EXTA_1 ...
EXTRACT EXTA_1 (PID 19061)
Current status:Recovery complete: At EOF
Current readposition:
Redo thread #: 1
Sequence #: 126
RBA: 16873472
Timestamp:2012-03-12 14:15:14.000000
SCN: 0.3919342
Current writeposition:
Sequence#: 12
RBA: 1570
Timestamp:2012-03-12 14:15:16.042348
Extract Trail:/ggs/dirdat/aa
GGSCI (oratest) 4>send dpa_1 status
Sending STATUS request to EXTRACT DPA_1 ...
EXTRACT DPA_1 (PID 19071)
Current status:Recovery complete: At EOF
Current readposition:
Sequence #: 12
RBA: 1570
Timestamp:2012-03-12 14:14:07.000000
Extract Trail:/ggs/dirdat/aa
Current writeposition:
Sequence #: 10
RBA: 1885
Timestamp:2012-03-12 14:15:17.150989
Extract Trail:F:\ggs_window\dirdat\aa
目标端进程信息:
GGSCI (WIN-AKOOCCILK8T) 18> send repa_1 status
Sending STATUS request to REPLICAT REPA_1 ...
Current status:At EOF
Sequence #: 10
RBA: 1885
0 records incurrent transaction
实验二:
在源端更新数据,目标端也更新。
源端更新数据:
SQL> select * from t1;
DEPTNODNAME LOC
---------- ------------------------------------------------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
SQL> update t1 set loc='a';
4 rows updated.
SQL> commit;
Commit complete.
SQL> select * from t1;
DEPTNODNAME LOC
---------- ------------------------------------------------------
10ACCOUNTING a
20RESEARCH a
30SALES a
40OPERATIONS a
查看目标端:
SQL> select *from t1
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING a
20RESEARCH a
30SALES a
40OPERATIONS a
说明源端更新数据,目标端也更新数据
实验三:未启用DDL时,源端增加或者减少表的某一个列或者新建表,同步到目标端。
在源端
SQL> create table t2 as select *from dept where 0=1;
Table created.
SQL> create unique index i2 on t2(deptno);
Index created.
目标端:
SQL> create table t2 as select * from dept where 0=1;
表已创建。
SQL> create unique index i2 on t2(deptno);
索引已创建。
在源端记录新加入表的日志
GGSCI (oratest) 22> add trandata scott.t2
Logging of supplemental redo data enabled for tableSCOTT.T2.
源端插入数据:
SQL> insert into t2 select * from dept;
4 rows created.
SQL> commit;
Commit complete.
SQL> select * from t2;
DEPTNODNAME LOC
---------- ------------------------------------------------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
目标端查看:
SQL> select * from t2;
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
在目标端增加一列:
SQL> select * from t2;
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40 OPERATIONS BOSTON
SQL> alter table t2 add lo varchar(10);
表已更改。
SQL> select * from t2;
DEPTNODNAME LOC LO
---------- -------------- ------------- ----------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
在源端增加一个列:
SQL> select * from t2;
DEPTNODNAME LOC
---------- ---------------------------- ----------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
SQL> alter table t2 add lo varchar(10);
Table altered.
SQL> select * from t2;
DEPTNODNAME LOC LO
---------- ------------------ ------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> update t2 set lo='a' where deptno=10;
1 row updated.
SQL> commit;
Commit complete.
在目标端查看:
SQL> select * from t2;
DEPTNO DNAME LOC LO
-------- -------------- ------------- ----------
10ACCOUNTING NEW YORK a
20RESEARCH DALLAS
30 SALES CHICAGO
40OPERATIONS BOSTON
实四:在源端表中有大量数据时,同步表中数据到目标端,目标端无此表,需要新建(数据初始化基于scn的初始化)。
对于静态初始化,把业务停掉,DB 上的数据就不会有变化,这时候,我们可以用expdp/impdp 或者dblink等方式把基数据同步过去,在启动相关的GG同步进程就可以了。
但如果要求零停机,DB事务就会不间断进行,可以通过如下两种方法来保证初始化过程中事务的完整性和数据的准确性呢
1. 利用 Keys + Handlecollisions
2. 利用 commit SCN/CSN
首先利用commit+scn/csn
1、清除之前的进程:
停止源端进程:
GGSCI (oratest) 18>stop exta_1
Sending STOP request to EXTRACT EXTA_1 ...
Request processed.
GGSCI (oratest) 22>stop dpa_1
Sending STOP request to EXTRACT DPA_1 ...
Request processed.
停止目标端进程:
GGSCI (WIN-AKOOCCILK8T) 14>stop repa_1
Sending STOP request to REPLICAT REPA_1 ...
Request processed.
删除源端的进程
GGSCI (oratest) 24> delete dpa_1
Deleted EXTRACT DPA_1.
GGSCI (oratest) 25>delete exta_1
Deleted EXTRACT EXTA_1.
删除目标端的进程
GGSCI (WIN-AKOOCCILK8T) 15>delete repa_1
Deleted REPLICAT REPA_1.
源端添加进程:
GGSCI (oratest) 31> dblogin userid goldengate passwordgoldengate
Successfully logged into database.
GGSCI (oratest) 33>add extract exta_1,tranlog,begin now
EXTRACT added
GGSCI (oratest) 35>add exttrail /ggs/dirdat/aa,extract exta_1
EXTTRAIL added.
GGSCI (oratest) 36> add extract dpa_1 exttrailsource /ggs/dirdat/aa
EXTRACT added.
GGSCI (oratest) 37>add rmttrail F:\ggs_window\dirdat\aa,extract dpa_1
RMTTRAIL added.
目标端添加进程:
GGSCI (WIN-AKOOCCILK8T) 16>add replicat repa_1,exttrail F:\ggs_window\dirdat\aa , nodbcheckpoint
REPLICAT added.
启动源端进程
GGSCI (oratest) 38>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED DPA_1 00:00:00 00:02:47
EXTRACT STOPPED EXTA_1 00:00:00 00:07:21
GGSCI (oratest) 39>start exta_1
Sending START request to MANAGER ...
EXTRACT EXTA_1 starting
GGSCI (oratest) 40>start dpa_1
Sending START request to MANAGER ...
EXTRACT DPA_1 starting
2、查看源端当前的scn
SQL> selectcurrent_scn from v$database;
CURRENT_SCN
-----------
4190059
3 、Expdp时源端表中的数据:
SQL> select *from scott.t4;
DEPTNODNAME LOC
---------- ---------------------------- ----------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
1 a a
2 a2 a
3 a3 a
4 a4 a
5 a5 a
6 a6 a
7 a7 a
DEPTNODNAME LOC
---------- ---------------------------- ----------
8 a8 a
9 a9 a
11 a11 a
12 a12 a
13 a13 a
14 a14 a
17 rows selected.
[root@oratest /]# mkdir /dump
[root@oratest /]#chownoracle:dba /dump
SQL> conn /as sysdba
Connected.
SQL> create directory dir as '/dump';
Directory created.
SQL> grantread,write on directory dir to scott;
Grant succeeded.
从源端将t3表中的数据导出;
[oracle@oratest dump]$expdp scott/tigerdirectory=dir dumpfile=t4.dmp tables=t4flashback_scn=4190059
Export: Release 11.2.0.1.0 - Production on Tue Mar 1314:28:53 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.Connected to: OracleDatabase 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and RealApplication Testing options.Starting"SCOTT"."SYS_EXPORT_TABLE_01": scott/******** directory=dir dumpfile=t4.dmptables=t4 flashback_scn=4078358
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object typeTABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "SCOTT"."T4" 6.093 KB 17 rows
Master table"SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
*********************************************************************Dumpfile set for SCOTT.SYS_EXPORT_TABLE_01 is:/dump/t4.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01"successfully completed at 14:28:59
3、更新源端表中的数据
SQL> update scott.t4 set loc='BB';
17 rows updated.
SQL> delete scott.t4where deptno=3;
1 row deleted.
SQL> commit;
Commit complete.
SQL> select *from scott.t4;
DEPTNODNAME LOC
---------- ------------------------------------------------------
10ACCOUNTING BB
20RESEARCH BB
30SALES BB
40OPERATIONS BB
1 a BB
2 a2 BB
4 a4 BB
5 a5 BB
6 a6 BB
7 a7 BB
8 a8 BB
DEPTNODNAME LOC
---------- ------------------------------------------------------
9 a9 BB
11 a11 BB
12 a12 BB
13 a13 BB
14 a14 BB
16 rows selected.
4、目标端impdp导入数据:
SQL> createdirectory dir as 'E:\';
目录已创建。
SQL> grantread,write on directory dir to scott;
授权成功。
C:\Users\Administrator>impdp scott/tiger directory=dir dumpfile=t4.dmp logfile=t4.log tables=t4table_exists_action=replace
Import: Release 11.2.0.1.0 - Production on星期二 3月 1314:35:28 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.连接到: Oracle Database 11g EnterpriseEdition Release 11.2.0.1.0 – Production。With thePartitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表"SCOTT"."SYS_IMPORT_TABLE_01"
启动 "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** directory=dir dumpfile=t4.dmplogfile=t4.log tables=t4 table_exists_action=replace
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
. . 导入了 "SCOTT"."T4" 6.093 KB 17 行
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
作业 "SCOTT"."SYS_IMPORT_TABLE_01"已于 14:35:32 成功完成
SQL> select *from t4;
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
1 a a
2 a2 a
3 a3 a
4 a4 a
5 a5 a
6 a6 a
7 a7 a
DEPTNODNAME LOC
---------- -------------- -------------
8 a8 a
9 a9 a
11 a11 a
12 a12 a
13 a13 a
14 a14 a
已选择17行。
目标端:
GGSCI (WIN-AKOOCCILK8T) 22>edit params repa_1
输入:
replicat repa_1
assumetargetdefs
userid goldengate,password goldengate
map scott.T1, target scott.T1;
map scott.T2, target scott.T2;
map scott.T3, target scott.T3;
map scott.T4, target scott.T4;
GGSCI (WIN-AKOOCCILK8T) 75> Start repa_1,aftercsn 4190059
Sending START request to MANAGER ...
REPLICAT REPA_1 starting
目标端查看数据,源端在impdp导出数据后,对t4表的更改已经同步到目标端
SQL> select * from t4;
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING BB
20RESEARCH BB
30SALES BB
40OPERATIONS BB
1 a BB
2 a2 BB
4 a4 BB
5 a5 BB
6 a6 BB
7 a7 BB
8 a8 BB
DEPTNODNAME LOC
---------- -------------- -------------
9 a9 BB
11 a11 BB
12 a12 BB
13 a13 BB
14 a14 BB
已选择16行。
实验四:DDL操作同步
DDL语句包含的主要语法如下:
DDL [
{INCLUDE | EXCLUDE}
[, MAPPED | UNMAPPED | OTHER | ALL]
[, OPTYPE <type>]
[, OBJTYPE ‘<type>’]
[, OBJNAME “<name>”]
[, INSTR ‘<string>’]
[, INSTRCOMMENTS ‘<comment_string>’]
例如:
DDL INCLUDEALL,EXCLUDE OBJNAME “hr.*”
DDL INCLUDE OBJNAME“fin.*” EXCLUDE “fin.ss”
DDL INCLUDE OPTYPEALTER
DDL INCLUDE OBJTYPE‘INDEX’
DDL INCLUDE OBJTYPE‘SNAPSHOT’
DDL INCLUDE OBJNAME“accounts.*”
在Extract和 Replicat进程中加入下面的内容:
ddl include all 同步除Oracle数据库自带的用户外所有用户的DDL操作
ddl includeallobjname user.*;只同步一个用户的数据
开启DDL同步的基本配置步骤为:
(1)关闭ORACLE的回收站功能。
(2)选择一个数据库schema存放支持DDL的GoldenGate对象,运行相应创建脚本。
(3)编辑globals参数文件。
(4)修改extl和repl的配置文件
清除DDL同步设置
SQL>@ddl_disable.sql --首先使DDL触发器失效
SQL>@ddl_remove.sql
SQL>@marker_remove.sql
SQL>@marker_status.sql
开始测试:
SQL>altersystem set recyclebin=offscope=both;
SQL> @ddl_setup.sql
GoldenGate DDL Replication setup script
Verifying that current user has privileges to install DDLReplication...
You will be prompted for the name of a schema for theGoldenGate database objects.NOTE: For an Oracle 10g source, the system recyclebin must be disabled. For Oracle 11g and later, it can be enabled.
NOTE: The schema must be created prior to running thisscript.
NOTE: Stop all DDL replication before starting thisinstallation.
Enter GoldenGate schema name:goldengate
You will be prompted for the mode of installation.
To install or reinstall DDL replication, enter INITIALSETUP
To upgrade DDL replication, enter NORMAL
Enter mode of installation:initialsetup
Working, please wait ...
Spooling to file ddl_setup_spool.txt
Checking for sessions that are holding locks on Oracle Golden Gatemetadata tables ...
Check complete.
SQL> grantggs_ggsuser_role to goldengate;
SQL> @role_setup.sql
GGS Role setup script
This script will drop and recreate the roleGGS_GGSUSER_ROLE
To use a different role name, quit this script and thenedit the params.sql script to change the gg_role parameter to the preferredname. (Do not run the script.)
You will be prompted for the name of a schema for theGoldenGate database objects.
NOTE: The schema must be created prior to running thisscript.
NOTE: Stop all DDL replication before starting thisinstallation.
Enter GoldenGate schema name:goldengate
Wrote file role_setup_set.txt
PL/SQL procedure successfully completed.
Role setup script complete
SQL>@ddl_enable.sql
Trigger altered.
修改源端抽取进程参数:
GGSCI (oratest) 55>edit params exta_1
extract exta_1
userid goldengate,password goldengate
exttrail /ggs/dirdat/aa
rmthost 10.10.8.54,mgrport 7809
ddl include mapped objname scott.*;
table scott.*;
GGSCI (oratest) 5>edit params dpa_1
extract dpa_1
passthru
rmthost 10.10.8.54,mgrport 7809
rmttrail F:\ggs_window\dirdat\aa
table scott.*;
修改目标端进程参数:
GGSCI (WIN-AKOOCCILK8T) 3> edit paramsrepa_1
replicat repa_1
assumetargetdefs
userid goldengate,password goldengate
ddl
map scott.*, target scott.*;
重启源端进程:
GGSCI (oratest) 81>start exta_1
Sending START request to MANAGER ...
EXTRACT EXTA_1 starting
GGSCI (oratest) 82>start dpa_1
Sending START request to MANAGER ...
EXTRACT DPA_1 starting
重启目标端进程:
GGSCI (WIN-AKOOCCILK8T) 5>start repa_1
Sending START request to MANAGER ...
REPLICAT REPA_1 starting
在源端创建一个张表tt2
SQL> createtable tt2 as select * from t3;
Table created.
目标端查询
SQL> select*from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
T1 TABLE
T2 TABLE
T3 TABLE
T4 TABLE
TT2 TABLE
已选择9行。
源端:
SQL> altertable tt2 add ll varchar(2);
Table altered.
SQL> select *from tt2;
DEPTNODNAME LOC LL
---------- ---------------------------- -------------------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40 OPERATIONS BOSTON
4 rows selected.
目标端:
SQL> select *from tt2;
DEPTNO DNAME LOC LL
-------- -------------- ------------- --
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30 SALES CHICAGO
40OPERATIONS BOSTON
在源端删除表:
SQL> drop table tt2;
Table dropped.
目标端查询:
SQL> select*from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$W8VyoP3zSAKj37FxqrksNA==$0 TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
T1 TABLE
T2 TABLE
T3 TABLE
T4 TABLE
已选择9行。
SQL> @ddl_disable.sql
Trigger altered.
关闭ddl后,不会自动同步ddl操作
一般goldengate做开启ddl,就需要关闭recyclebin
Alter system set recyclebin=off
实验五:truncate操作同步
停止所有进程:
GGSCI (oratest) 9> stop exta_1
Sending STOP request to EXTRACT EXTA_1 ...
Request processed.
GGSCI (oratest) 12> stop dpa_1
Sending STOP request to EXTRACT DPA_1 ...
Request processed.
GGSCI (WIN-AKOOCCILK8T) 5> stop repa_1
Sending STOP request to REPLICAT REPA_1 ...
Request processed.
修改参数文件:
在源端添加参数gettruncates
GGSCI (oratest) 7>edit params exta_1
extract exta_1
userid goldengate,password goldengate
exttrail /ggs/dirdat/aa
rmthost 10.10.8.54,mgrport 7809
ddl include mapped objname scott.*;
gettruncates
table scott.*;
在目标端添加参数gettruncates
GGSCI (WIN-AKOOCCILK8T) 29>edit params repa_1
replicat repa_1
assumetargetdefs
userid goldengate,password goldengate
ddl
gettruncates
map scott.*, target scott.*;
重启源端和目标端的进程:
GGSCI (oratest) 2>start exta_1
Sending START request to MANAGER ...
EXTRACT EXTA_1 starting
GGSCI (oratest) 3>start dpa_1
Sending START request to MANAGER ...
EXTRACT DPA_1 starting
GGSCI (oratest) 4>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DPA_1 00:00:00 00:00:00
EXTRACT RUNNING EXTA_1 00:00:00 00:00:03
GGSCI (WIN-AKOOCCILK8T) 11>start repa_1
Sending START request to MANAGER ...
REPLICAT REPA_1 starting
源端查看表t1:
SQL> select *from t1;
DEPTNODNAME LOC
---------- ---------- --------------------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
目标端查看表t1:
SQL> select *from t1;
DEPTNO DNAME LOC
---------- -------------- -------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30SALES CHICAGO
40OPERATIONS BOSTON
源端truncate:
SQL> truncatetable t1;
Table truncated.
目标端查看:
SQL> select *from t1;
未选定行
实验六:可以让不同的进程管理不同的表(在实验五的基础上添加新的进程)
GGSCI (oratest) 57>stop exta_1
Sending STOP request to EXTRACT EXTA_1 ...
Request processed.
GGSCI (oratest) 58>stop dpa_1
Sending STOP request to EXTRACT DPA_1 ...
Request processed.
GGSCI (WIN-AKOOCCILK8T) 5>stop repa_1
Sending STOP request to REPLICAT REPA_1 ...
Request processed.
GGSCI (oratest) 59>addextract exta_a,tranlog,begin now
GGSCI (oratest) 60>add exttrail /ggs/dirdat/bb,extract exta_a
GGSCI (oratest) 61>view params exta_a
extract exta_a
userid goldengate password goldengate
exttrail /ggs/dirdat/bb
rmthost 10.10.8.54,mgrport 7809
ddl include all objname scott.t5;
table scott.t5;
GGSCI (oratest) 62>addextract dpa_a,exttrailsource /ggs/dirdat/bb
GGSCI (oratest) 65>add rmttrail F:\ggs_window\dirdat\bb,extract dpa_a
GGSCI (oratest) 73>view params dpa_a
extract dpa_a
userid goldengate password goldengate
rmthost 10.10.8.54,mgrport 7809
rmttrail F:\ggs_window\dirdat\bb
passthru
table scott.t5;
GGSCI (WIN-AKOOCCILK8T) 6>edit param ./GLOBALS
ggschema goldengate
checkpoint goldengate.checkpoint
GGSCI (WIN-AKOOCCILK8T) 7>dblogin userid goldengate password goldengate
GGSCI (WIN-AKOOCCILK8T) 8>add checkpointtable goldengate.checkpoint
GGSCI (WIN-AKOOCCILK8T) 9>edit params repa_a
replicat repa_a
assumetargetdefs
userid goldengate,password goldengate
map scott.t5 ,target scott.t5;
GGSCI (oratest) 59>start exta_1
Sending START request to MANAGER ...
EXTRACT EXTA_1 starting
GGSCI (oratest) 60>start dpa_1
Sending START request to MANAGER ...
EXTRACT DPA_1 starting
GGSCI (oratest) 62> start exta_a
Sending START request to MANAGER ...
EXTRACT EXTA_A starting
GGSCI (oratest) 64>start dpa_a
Sending START request to MANAGER ...
EXTRACT DPA_A starting
GGSCI (oratest) 61>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DPA_1 00:00:00 00:02:17
EXTRACT ABENDED DPA_A 00:00:00 00:08:16
EXTRACT RUNNING EXTA_1 00:02:28 00:00:06
EXTRACT RUNNING EXTA_A 00:00:00 00:00:00
GGSCI (WIN-AKOOCCILK8T) 51>start repa_1
Sending START request to MANAGER ...
REPLICAT REPA_1 starting
GGSCI (WIN-AKOOCCILK8T) 51>start repa_a
Sending START request to MANAGER ...
REPLICAT REPA_A starting
在源端创建表:
Create table t5 as select * from dept;
Create unique index i5 on t5(deptno);
在目标端创建表:
Create table t5 as select * from dept;
Create unique index i5 on t5(deptno);
在源端插入数据
SQL> declare
2 i number;
3 t_count number;
4 m number;
5 begin
6 i:=1;
7 m:=0;
8 t_count:=10;
9 select nvl(max(deptno),0) into m fromscott.t5;
10 if t_count>0 then
11 while i<=t_count loop
12 insert into scott.t5 (deptno,dname,loc)values (m+i,'badf','aaa');
13 if mod(i,100)=0 or i>=t_count then
14 commit;
15 end if;
16 i:=i+1;
17 end loop;
18 end if;
19 exception when others then
20 rollback;
21 end;
22 /
PL/SQL procedure successfully completed.
SQL> select *from t5;
DEPTNODNAME LOC
---------- ------------------------------------------------------
1badf aaa
2badf aaa
3 badf aaa
4badf aaa
5badf aaa
6badf aaa
7badf aaa
8badf aaa
9badf aaa
10badf aaa
10 rows selected.
目标端查看:
SQL> select *from t5;
DEPTNODNAME LOC
---------- -------------- -------------
1badf aaa
2 badf aaa
3badf aaa
4badf aaa
5badf aaa
6badf aaa
7badf aaa
8badf aaa
9badf aaa
10badf aaa
已选择10行。
在源端:
SQL> createtable t1 as select * from dept;
Table created.
目标端查看:
SQL> select *from t1;
DEPTNODNAME LOC
---------- -------------- -------------
10ACCOUNTING NEW YORK
20RESEARCH DALLAS
30 SALES CHICAGO
40OPERATIONS BOSTON
在源端:
SQL> truncatetable t1;
Table truncated.
目标端:
SQL> select *from t1;
未选定行
遇到的问题:
源端:
GGSCI (oratest) 84> info exta_1
EXTRACT EXTA_1 Last Started 2012-03-1311:49 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:49:53 ago)
Log Read Checkpoint Oracle Redo Logs
2012-03-13 11:51:47 Thread 1,Seqno 131, RBA 29594112
GGSCI (oratest) 86> info dpa_1
EXTRACT DPA_1 Initialized 2012-03-13 11:49 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:49:33 ago)
Log Read Checkpoint File /ggs/dirdat/aa000019
First Record RBA 668652
目标端:
GGSCI (WIN-AKOOCCILK8T) 62> info repa_1
REPLICAT REPA_1 Last Started 2012-03-1311:50 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:49:43 ago)
Log Read Checkpoint File F:\ggs_window\dirdat\aa000016
First Record RBA 1465
解放方法:
alter extract dpa_1,etrollover
alter extract exta_1,etrollover
GGSCI (WIN-AKOOCCILK8T) 69> alter replicat repa_1extseqno 21,extrba 0
目标端:
2012-03-15 11:04:26 WARNING OGG-01004 Aborted groupedtransaction on 'SCOTT.T1', Database error 1403 ().
2012-03-15 11:04:26 WARNING OGG-01003 Repositioningto rba 1201 in seqno 4.
2012-03-15 11:04:26 WARNING OGG-01154 SQL error 1403mapping SCOTT.T1 to SCOTT.T1.
2012-03-15 11:04:26 WARNING OGG-01003 Repositioningto rba 1201 in seqno 4.
查看源端信息:
GGSCI (oratest) 5> send dpa_1 status
Sending STATUS request to EXTRACT DPA_1 ...
EXTRACT DPA_1 (PID 22959)
Current status: Recovery complete: At EOF
Current readposition:
Sequence #: 6
RBA: 1486
Timestamp:2012-03-15 11:03:33.000000
Extract Trail:/ggs/dirdat/aa
Current writeposition:
Sequence #: 4
RBA: 1669
Timestamp:2012-03-15 11:11:06.772586
Extract Trail:F:\ggs_window\dirdat\aa
目标端进程append
解决方法:
目标端执行
alter replicat repa_1 extseqno 4,extrba 1669
常用的语句:
alter extract dpa_1,etrollover
alterextract exta_1,etrollover
只能在 pump extract or replicat上用:
alterextract dpa_1 extseqno 24,extrba 1018
alterreplicat repa_1 extseqno 6,extrba 2547
alter extract repa_1 extseqno 6,extrba 2547
alter extract exta_1,extseqno 13,extrba 1909
alter extract dpa_1,extseqno 13,extrba 1909
send exta_1 status
info exta_1 status,showch
info all
view report exta_1
edit parameter exta_1
lag exta_1 查看进程延迟
stats exta_1
错误:
Reading/ggs/dirdat/aa000000, current RBA 935, 0 records
Reportat 2012-05-31 17:05:33 (activity since 2012-05-31 17:05:33)
Norecords were replicated.
Lastlog location read:
FILE: /ggs/dirdat/aa000000
SEQNO: 0
RBA: 935
TIMESTAMP: 2012-05-31 16:52:55.952608
EOF: NO
READERR: 0
2012-05-3117:05:33 ERROR OGG-01668 PROCESS ABENDING.
CACHEOBJECT MANAGER statistics
alter replicat repa extseqno 1,extrba 559
delete extract exta
delete extract dpa
delete replicat repa
add extract exta ,tranlog,begin now
addexttrail /ggs/dirdat/aa,extract exta
addextract dpa ,exttrailsource/ggs/dirdat/aa
add rmttrail d:\ggs\dirdat\aa extract dpa
add replicat repa, exttrail d:\ggs\dirdat\aa ,nodbcheckpoint