Oracle GoldenGate DDL同步配置
在上一篇博文中实验已经配置好了OGG的DML双向同步。下面是在此基础上配置增加DDL的同步配置。
[项目环境]
|
Item |
Primary System |
Secondary System |
|
Platform |
RHEL5.5 |
RHEL5.5 |
|
Hostname |
lvxinghao1 |
lvxinghao2 |
|
Database |
Oracle10.2.0.1 |
Oracle 10.2.0.1 |
|
Character Set |
ZHS16GBK |
ZHS16GBK |
|
ORACLE_SID |
prod |
test1 |
|
Listener Name/Port |
LISTENER/1521 |
LISTENER/1521 |
|
Goldengate User |
ogg |
ogg |

[实施步骤]
先进入goldengate软件安装目录,以SYSDBA身份登录oracle执行以下脚本,执行脚本过程中,需要输入的用户全部是ogg,安装模式为INITIALSETUP,如果数据字典或者某些内部的包有错误,则需要运行catalog.sql和catproc.sql脚本。
如果某项脚本执行错误,需要重新执行时,先要执行清除的脚本:ddl_remove.sql和marker_remove.sql
|
[oracle@lvxinghao1 ~]$ cd /u01/app/ogg [oracle@lvxinghao1 ogg]$ sqlplus '/as sysdba' |
|
SYS@ prod>@marker_setup Marker setup script You will be prompted for the name of a schema for the GoldenGate database objects. NOTE: The schema must be created prior to running this script. NOTE: Stop all DDL replication before starting this installation. Enter GoldenGate schema name:ogg Marker setup table script complete, running verification script... Please enter the name of a schema for the GoldenGate database objects: Setting schema name to OGG MARKER TABLE ------------------------------- OK MARKER SEQUENCE ------------------------------- OK Script complete. |
|
SYS@ prod>alter system set recyclebin='off' scope=both; SYS@ prod>show parameter recyclebin NAME TYPE VALUE ------------------------------------ ----------- -------------- recyclebin string off
SYS@ prod>@ddl_setup GoldenGate DDL Replication setup script Verifying that current user has privileges to install DDL Replication... You will be prompted for the name of a schema for the GoldenGate database objects. NOTE: The schema must be created prior to running this script. NOTE: On Oracle 10g and up, system recycle bin must be disabled. NOTE: Stop all DDL replication before starting this installation. Enter GoldenGate schema name:ogg 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 Using OGG as a GoldenGate schema name, INITIALSETUP as a mode of installation. Working, please wait ... RECYCLEBIN must be empty. This installation will purge RECYCLEBIN for all users. To proceed, enter yes. To stop installation, enter no. Enter yes or no:yes DDL replication setup script complete, running verification script... Please enter the name of a schema for the GoldenGate database objects: Setting schema name to OGG DDLORA_GETTABLESPACESIZE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors CLEAR_TRACE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors CREATE_TRACE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors TRACE_PUT_LINE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors INITIAL_SETUP STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDLVERSIONSPECIFIC PACKAGE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDLREPLICATION PACKAGE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDLREPLICATION PACKAGE BODY STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDL HISTORY TABLE ----------------------------------- OK DDL HISTORY TABLE(1) ----------------------------------- OK DDL DUMP TABLES ----------------------------------- OK DDL DUMP COLUMNS ----------------------------------- OK DDL DUMP LOG GROUPS ----------------------------------- OK DDL DUMP PARTITIONS ----------------------------------- OK DDL DUMP PRIMARY KEYS ----------------------------------- OK DDL SEQUENCE ----------------------------------- OK GGS_TEMP_COLS ----------------------------------- OK GGS_TEMP_UK ----------------------------------- OK DDL TRIGGER CODE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDL TRIGGER INSTALL STATUS ----------------------------------- OK DDL TRIGGER RUNNING STATUS ---------------------------------------------------------------------- ENABLED STAYMETADATA IN TRIGGER ---------------------------------------------------------------------- OFF DDL TRIGGER SQL TRACING ---------------------------------------------------------------------- 0 DDL TRIGGER TRACE LEVEL ----------------------------------------------- 0 LOCATION OF DDL TRACE FILE ---------------------------------------------------------------------------- /u01/app/oracle/admin/prod/udump/ggs_ddl_trace.log Analyzing installation status... STATUS OF DDL REPLICATION ------------------------------------------------------------------------------------------------------------------------ SUCCESSFUL installation of DDL Replication software components Script complete.
|
|
SYS@ prod>@role_setup GGS Role setup script This script will drop and recreate the role GGS_GGSUSER_ROLE To use a different role name, quit this script and then edit the params.sql script to change the gg_role parameter to the preferred name. (Do not run the script.) You will be prompted for the name of a schema for the GoldenGate database objects. NOTE: The schema must be created prior to running this script. NOTE: Stop all DDL replication before starting this installation. Enter GoldenGate schema name:ogg Wrote file role_setup_set.txt PL/SQL procedure successfully completed. Role setup script complete Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command:
GRANT GGS_GGSUSER_ROLE TO
where
|
|
SYS@ prod>grant GGS_GGSUSER_ROLE TO ogg; Grant succeeded. SUCCESSFUL installation of DDL Replication software components Script complete.
|
|
SYS@ prod>@ddl_enable Trigger altered. |
|
[oracle@lvxinghao2 ~]$ cd /u01/app/ogg [oracle@lvxinghao2 ogg]$ sqlplus '/as sysdba' |
|
SYS@ test1> @marker_setup Marker setup script You will be prompted for the name of a schema for the GoldenGate database objects. NOTE: The schema must be created prior to running this script. NOTE: Stop all DDL replication before starting this installation. Enter GoldenGate schema name:ogg Marker setup table script complete, running verification script... Please enter the name of a schema for the GoldenGate database objects: Setting schema name to OGG MARKER TABLE ------------------------------- OK MARKER SEQUENCE ------------------------------- OK Script complete. |
|
SYS@ test1>alter system set recyclebin='off' scope=both; SYS@ test1>show parameter recyclebin
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ recyclebin string off SYS@ test1>@ddl_setup GoldenGate DDL Replication setup script Verifying that current user has privileges to install DDL Replication... You will be prompted for the name of a schema for the GoldenGate database objects. NOTE: The schema must be created prior to running this script. NOTE: On Oracle 10g and up, system recycle bin must be disabled. NOTE: Stop all DDL replication before starting this installation. Enter GoldenGate schema name:ogg 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 Using OGG as a GoldenGate schema name, INITIALSETUP as a mode of installation. Working, please wait ... RECYCLEBIN must be empty. This installation will purge RECYCLEBIN for all users. To proceed, enter yes. To stop installation, enter no. Enter yes or no:yes DDL replication setup script complete, running verification script... Please enter the name of a schema for the GoldenGate database objects: Setting schema name to OGG DDLORA_GETTABLESPACESIZE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors CLEAR_TRACE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors CREATE_TRACE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors TRACE_PUT_LINE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors INITIAL_SETUP STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDLVERSIONSPECIFIC PACKAGE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDLREPLICATION PACKAGE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDLREPLICATION PACKAGE BODY STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDL HISTORY TABLE ----------------------------------- OK DDL HISTORY TABLE(1) ----------------------------------- OK DDL DUMP TABLES ----------------------------------- OK DDL DUMP COLUMNS ----------------------------------- OK DDL DUMP LOG GROUPS ----------------------------------- OK DDL DUMP PARTITIONS ----------------------------------- OK DDL DUMP PRIMARY KEYS ----------------------------------- OK DDL SEQUENCE ----------------------------------- OK GGS_TEMP_COLS ----------------------------------- OK GGS_TEMP_UK ----------------------------------- OK DDL TRIGGER CODE STATUS: Line/pos Error -------------------- ----------------------------------------------------------------- No errors No errors DDL TRIGGER INSTALL STATUS ----------------------------------- OK DDL TRIGGER RUNNING STATUS ---------------------------------------------------------------------- ENABLED STAYMETADATA IN TRIGGER ---------------------------------------------------------------------- OFF DDL TRIGGER SQL TRACING ---------------------------------------------------------------------- 0 DDL TRIGGER TRACE LEVEL ----------------------------------------------- 0 LOCATION OF DDL TRACE FILE ---------------------------------------------------------------------------- /u01/app/oracle/admin/ test1/udump/ggs_ddl_trace.log Analyzing installation status... STATUS OF DDL REPLICATION -------------- SUCCESSFUL installation of DDL Replication software components Script complete.
|
|
SYS@ test1> @role_setup GGS Role setup script This script will drop and recreate the role GGS_GGSUSER_ROLE To use a different role name, quit this script and then edit the params.sql script to change the gg_role parameter to the preferred name. (Do not run the script.) You will be prompted for the name of a schema for the GoldenGate database objects. NOTE: The schema must be created prior to running this script. NOTE: Stop all DDL replication before starting this installation. Enter GoldenGate schema name:ogg Wrote file role_setup_set.txt PL/SQL procedure successfully completed. Role setup script complete Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command:
GRANT GGS_GGSUSER_ROLE TO
where
|
|
SYS@ test1> grant GGS_GGSUSER_ROLE TO ogg; Grant succeeded. SUCCESSFUL installation of DDL Replication software components Script complete.
|
|
SYS@ test1> @ddl_enable Trigger altered. |
先关闭eora_1、eora_2进程,在eora_1、eora_2配置文件中添加以下一行,然后重新启动:
DDL INCLUDE OBJNAME "scott.*"
|
GGSCI (lvxinghao2) 39> DBLOGIN USERID ogg, PASSWORD ogg Successfully logged into database. |
|
Stop extract process GGSCI (lvxinghao1) 21> stop extract eora_1 Sending STOP request to EXTRACT EORA_1 ... Request processed.
Edit extract process EORA_1 parameter GGSCI (lvxinghao1) 22> edit params eora_1 -- Change Capture parameter file to capture --scott.* changes EXTRACT EORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) USERID ogg, PASSWORD ogg TRANLOGOPTIONS EXCLUDEUSER ogg DDL INCLUDE OBJNAME "scott.*" EXTTRAIL ./dirdat/aa TABLE scott.*;
Start extract process EORA_1 GGSCI (lvxinghao1) 24> start extract eora_1 Sending START request to MANAGER ... EXTRACT EORA_1 starting
Verify GGSCI (lvxinghao1) 25> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_1 00:02:27 00:00:02 EXTRACT RUNNING PORA_1 00:00:00 00:00:07 REPLICAT RUNNING RORA_2 00:00:00 00:00:06 |
|
Stop extract process GGSCI (lvxinghao2) 23> stop extract eora_2 Sending STOP request to EXTRACT EORA_2 ... Request processed.
Edit extract process EORA_2 parameter GGSCI (lvxinghao2) 24> edit params eora_2 -- Change Capture parameter file to capture --scott.* changes EXTRACT EORA_2 SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) USERID ogg, PASSWORD ogg TRANLOGOPTIONS EXCLUDEUSER ogg DDL INCLUDE OBJNAME "scott.*" EXTTRAIL ./dirdat/ab TABLE scott.*;
Start extract process GGSCI (lvxinghao2) 25> start extract eora_2 Sending START request to MANAGER ... EXTRACT EORA_2 starting
Verify GGSCI (lvxinghao2) 26> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_2 00:01:00 00:00:02 EXTRACT RUNNING PORA_2 00:00:00 00:00:08 REPLICAT RUNNING RORA_1 00:00:00 00:00:09 |
配置REPLICAT进程参数文件,添加以下几行到rora_1/rora_2配置文件中:
DDL INCLUDE ALL
DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 3 RETRYDELAY 5
DDLERROR DEFAULT DISCARD
DDLERROR DEFAULT IGNORE RETRYOP
|
Stop Replicat process: GGSCI (lvxinghao2) 28> stop replicat rora_1 Sending STOP request to REPLICAT RORA_1 ... Request processed.
Edit replicat process RORA_1 parameter GGSCI (lvxinghao2) 29> edit params rora_1 -- Change Delivery parameter file to apply -- lvxinghao Changes REPLICAT RORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) USERID ogg, PASSWORD ogg HANDLECOLLISIONS ASSUMETARGETDEFS DISCARDFILE ./dirrpt/RORA_aa.DSC, PURGE DDL INCLUDE ALL DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 3 RETRYDELAY 5 DDLERROR DEFAULT DISCARD DDLERROR DEFAULT IGNORE RETRYOP MAP scott.*, TARGET scott.*;
Start Replicat process: GGSCI (lvxinghao2) 30> start replicat rora_1 Sending START request to MANAGER ... REPLICAT RORA_1 starting
Verify GGSCI (lvxinghao2) 31> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_2 00:00:00 00:00:07 EXTRACT RUNNING PORA_2 00:00:00 00:00:09 REPLICAT RUNNING RORA_1 00:00:00 00:00:03 |
Edit replicat process RORA_1 parameter:
GGSCI (lvxinghao2) 4> EDIT PARAM RORA_1
Add:
--
-- Change Delivery parameter file to apply
-- lvxinghao Changes
--
REPLICAT RORA_1
SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
USERID ogg, PASSWORD ogg
HANDLECOLLISIONS
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/RORA_aa.DSC, PURGE
MAP scott.lvxinghao, TARGET scott.lvxinghao;
Note: In the MAP statement, the first owner/schema is for the source and the second for the target.
Start Replicat process:
GGSCI (lvxinghao2) 5> START REPLICAT RORA_1
Sending START request to MANAGER ...
REPLICAT RORA_1 starting
Verify:
GGSCI (lvxinghao2) 6> info replicat rora_1
REPLICAT RORA_1 Last Started 2014-09-13 21:09 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:07 ago)
Log Read Checkpoint File ./dirdat/pa000000
First Record RBA 0
|
Stop Replicat process: GGSCI (lvxinghao1) 28> stop replicat rora_2 Sending STOP request to REPLICAT RORA_2 ... Request processed.
Edit replicat process RORA_2 parameter GGSCI (lvxinghao1) 31> edit params rora_2 -- Change Delivery parameter file to apply -- lvxinghao Changes REPLICAT RORA_2 SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) USERID ogg, PASSWORD ogg HANDLECOLLISIONS ASSUMETARGETDEFS DISCARDFILE ./dirrpt/RORA_ab.DSC, PURGE DDL INCLUDE ALL DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 3 RETRYDELAY 5 DDLERROR DEFAULT DISCARD DDLERROR DEFAULT IGNORE RETRYOP MAP scott.*, TARGET scott.*;
Start Replicat process: GGSCI (lvxinghao1) 32> start replicat rora_2 Sending START request to MANAGER ... REPLICAT RORA_2 starting
Verify GGSCI (lvxinghao1) 33> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_1 00:00:00 00:00:08 EXTRACT RUNNING PORA_1 00:00:00 00:00:05 REPLICAT RUNNING RORA_2 00:00:00 00:00:02 |
|
SCOTT@ test1>create table beyond as select * from emp; Table created. SCOTT@ test1>alter table beyond add constraint beyond_empno_pk primary key(empno); Table altered. |
|
SCOTT@ prod>select * from tab; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- DEPT TABLE BONUS TABLE EMP TABLE SALGRADE TABLE EMP2 TABLE LVXINGHAO TABLE BEYOND TABLE
SCOTT@ prod>SELECT I.INDEX_NAME,I.index_TYPE,C.COLUMN_NAME 2 FROM USER_INDEXES I,USER_IND_COLUMNS C 3 WHERE I.TABLE_NAME='BEYOND' 4 AND I.INDEX_NAME=C.INDEX_NAME; INDEX_NAME INDEX_TYPE COLUMN_NAME -------------------- ---------- --------------- BEYOND_EMPNO_PK NORMAL EMPNO |
在test1端创建新表、添加主键约束。在prod端查看已经同步。
|
GGSCI (lvxinghao1) 49> info trandata scott.beyond Logging of supplemental redo log data is disabled for table SCOTT.BEYOND.
GGSCI (lvxinghao2) 48> info trandata scott.beyond Logging of supplemental redo log data is disabled for table SCOTT.BEYOND.
|
|
GGSCI (lvxinghao2) 49> stop replicat rora_1 Sending STOP request to REPLICAT RORA_1 ... Request processed. GGSCI (lvxinghao1) 50> stop replicat rora_2 Sending STOP request to REPLICAT RORA_2 ... Request processed.
|
|
GGSCI (lvxinghao2) 50> add trandata scott.beyond Logging of supplemental redo data enabled for table SCOTT.BEYOND. GGSCI (lvxinghao1) 51> add trandata scott.beyond Logging of supplemental redo data enabled for table SCOTT.BEYOND.
|
|
GGSCI (lvxinghao1) 52> start replicat rora_2 Sending START request to MANAGER ... REPLICAT RORA_2 starting
GGSCI (lvxinghao2) 51> start replicat rora_1 Sending START request to MANAGER ... REPLICAT RORA_1 starting |
|
GGSCI (lvxinghao1) 53> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_1 00:00:00 00:00:07 EXTRACT RUNNING PORA_1 00:00:00 00:00:07 REPLICAT RUNNING RORA_2 00:00:00 00:00:02 GGSCI (lvxinghao2) 52> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_2 00:00:00 00:00:06 EXTRACT RUNNING PORA_2 00:00:00 00:00:09 REPLICAT RUNNING RORA_1 00:00:00 00:00:09 |
4.3 DML:Update operations on the new created table
|
SCOTT@ test1>update beyond set ename='DAMON' where empno=7788; SCOTT@ test1>commit; |
|
SCOTT@ prod>select * from beyond; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ------ ------- --------- ------ ------------------- ------ ------ ------- 7788 DAMON ANALYST 7566 1987-04-19 00:00:00 3000 20 7839 KING PRESIDENT 1981-11-17 00:00:00 5000 10 7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30 7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20 7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30 7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20 7934 MILLER CLERK 7782 1982-01-23 00:00:00 1300 10 7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20 7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30 7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30 7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20 7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30 7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30 7782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10 14 rows selected. |
在test1上对scott.beyond表进行update操作,在prod端查看已经同步。
|
SCOTT@ prod>drop table beyond; Table dropped. |
|
SCOTT@ test1>select * from tab; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- DEPT TABLE EMP TABLE BONUS TABLE SALGRADE TABLE LVXINGHAO TABLE EMP2 TABLE 6 rows selected. |
在prod上删除scott.beyond表后,在test1上查看,此表也已经被删除。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29475508/viewspace-1290169/ ,如需转载,请注明出处,否则将追究法律责任。