1.创建初始数据
SQL> create table testogg.dept as select * from scott.dept;
2.配置MGR进程
GGSCI (dgdb1) 30> edit param mgr
port 7809
3.启动MGR进程
GGSCI (dgdb1) 31> start mgr
4.配置抽取进程
GGSCI (dgdb1) 33> add ext extc,tranlog,begin now
EXTRACT added.
5.配置抽取进程本地队列
GGSCI (dgdb1) 34> add exttrail /home/oracle/ogg/dirdat/lc,ext extc,megabytes 20
EXTTRAIL added.
6.配置抽取进程参数
GGSCI (dgdb1) 35> edit param extc
EXTRACT extc
setenv ( NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
setenv (ORACLE_SID = oggdb)
USERID goldengate, PASSWORD goldengate
EXTTRAIL /home/oracle/ogg/dirdat/lc
dynamicresolution
table testogg.dept;
7.配置传输进程
GGSCI (dgdb1) 36> add ext dpec,exttrailsource /home/oracle/ogg/dirdat/lc
EXTRACT added.
8.配置传输进程远程队列
GGSCI (dgdb1) 37> add rmttrail /home/oracle/ogg/dirdat/rc,ext dpec,megabytes 20
RMTTRAIL added.
9.配置传输进程参数
GGSCI (dgdb1) 38> edit param dpec
extract dpec
setenv ( NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
passthru
rmthost 192.168.162.81,mgrport 7809, compress
rmttrail /home/oracle/ogg/dirdat/rc
dynamicresolution
table testogg.dept;
10.添加表级附加日志
GGSCI (dgdb1) 40> dblogin userid goldengate, password goldengate
Successfully logged into database.
GGSCI (dgdb1) 41> add trandata testogg.dept
11.启动抽取进程
GGSCI (dgdb1) 42> start extc
Sending START request to MANAGER ...
EXTRACT EXTC starting
12.启动传输进程
GGSCI (dgdb1) 43> start dpec
Sending START request to MANAGER ...
EXTRACT DPEC starting
13.查看源端进程状态
GGSCI (dgdb1) 44> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     DPEC        00:00:00      00:01:19
EXTRACT     RUNNING     EXTC        00:01:45      00:00:07
14.获取当前数据库scn
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
    1106419
15.根据当前SCN导出表数据
[oracle@dgdb1 ogg]$ expdp testogg/oracle directory=oggdir dumpfile=oggtest_dept.dmp logfile=oggtest_dept.log tables=dept flashback_scn=1106419
16.把导出文件传输到目标端
[oracle@dgdb1 ogg]$ scp /home/oracle/oggtest_dept.dmp oracle@dgdb2:/home/oracle
17.目标端创建用户并授予权限(测试给的dba权限)
SQL> create user testogg identified by oracle account unlock;
User created.
SQL> grant dba to testogg;
Grant succeeded.
18.目标端导入表数据
[oracle@dgdb2 ~]$ impdp testogg/oracle directory=oggdir dumpfile=oggtest_dept.dmp logfile=oggtest_dept.log tables=dept
19.配置投递进程
GGSCI (dgdb2) 28> add rep repc,exttrail /home/oracle/ogg/dirdat/rc,nodbcheckpoint
REPLICAT added.
20.配置投递进程参数
GGSCI (dgdb2) 29> edit param repc
replicat repc
setenv ( NLS_LANG = AMERICAN_AMERICA.ZHS16GBK)
setenv (ORACLE_SID = destdb)
userid goldengate, password goldengate
reperror default,abend
discardfile /home/oracle/ogg/dirrpt/repc.dsc,append, megabytes 10
assumetargetdefs
dynamicresolution
map testogg.dept, target testogg.dept;
21.启动投递进程
GGSCI (dgdb2) 31> start repc,aftercsn 1106419
Sending START request to MANAGER ...
REPLICAT REPC starting
22.查看目标端进程状态
GGSCI (dgdb2) 32> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING
REPLICAT    RUNNING     REPC        00:00:00      00:00:01
23.测试OGG同步
源端插入数据:
SQL> insert into dept values (50,'manage','golddentstat');
SQL> commit;
SQL> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 manage         golddentstat
		
目标端查询:
SQL> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 manage         golddentstat
		
源端更新数据:
SQL> update dept set loc='golddentstate' where deptno=50;
1 row updated.
SQL> commit;
SQL> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 manage         golddentstate
目标端查询数据:
SQL> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 manage         golddentstate
		
源端查看进程信息:
GGSCI (dgdb1) 47> stats extc
Sending STATS request to EXTRACT EXTC ...
Start of Statistics at 2022-07-02 01:48:15.
Output to /home/oracle/ogg/dirdat/lc:
Extracting from TESTOGG.DEPT to TESTOGG.DEPT:
*** Total statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Daily statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Hourly statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Latest statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
End of Statistics.
GGSCI (dgdb1) 48> stats dpec
Sending STATS request to EXTRACT DPEC ...
Start of Statistics at 2022-07-02 01:48:21.
Output to /home/oracle/ogg/dirdat/rc:
Extracting from TESTOGG.DEPT to TESTOGG.DEPT:
*** Total statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Daily statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Hourly statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Latest statistics since 2022-07-02 01:29:38 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
End of Statistics.
GGSCI (dgdb1) 49>
目标端查询进程信息:
GGSCI (dgdb2) 34> stats repc
Sending STATS request to REPLICAT REPC ...
Start of Statistics at 2022-07-02 01:48:54.
Replicating from TESTOGG.DEPT to TESTOGG.DEPT:
*** Total statistics since 2022-07-02 01:29:41 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Daily statistics since 2022-07-02 01:29:41 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Hourly statistics since 2022-07-02 01:29:41 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
*** Latest statistics since 2022-07-02 01:29:41 ***
        Total inserts                                      1.00
        Total updates                                      1.00
        Total deletes                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00
End of Statistics.