GoldenGate DDL配置详解(原创)

前言

OS:RHEL 5.4   Oracle:10.2.0.1   GoldenGate:11.2.0.1 For Oracle 10g

注意事项:

1、用户的默认表空间不要指定为SYSTEM,否则在初始化DDL支持时可能会遇到段无法扩展,或包无法编译等错误。
正式应用的话,需要注意ogg用户所在表空间是否有充足的空间。

2、以SYSDBA身份登录到SQL*Plus,此时应该断开所有连接到ORACLE数据库的会话,并且不再允许创建新会话,仅保留刚刚创建的SYSDBA身份登录的SQL*Plus。 

配置DDL支持

1、关闭数据库回收站:

SQL>alter system set recyclebin=off scope=both;

2、编辑globals参数文件,标明支持DDL的GG对象存放在哪个schema下:

GGSCI>view param ./globals

GGSCHEMA ogg  

如果由于某些特殊的需求自定义DDL相关对象的名称的话,可以通过重定义位于GoldenGate软件安装目录下params.sql文件中的相关变量值,再配置GLOBALS,新增对象名称的对应关系,例如:
MARKERTABLE <new_table_name>
DDLTABLE <new_table_name> 
前者表示Marker表,后一个表示DDL历史表。

一般情况下不需要修改,ORACLE也建议保持数据库对象默认值,该操作为可选操作

3、执行所需脚本

备忘清单

marker_setup.sql

ddl_setup.sql

role_setup.sql

Grant the role to all GoldenGate Extract users

ddl_enable.sql

install and use the optional performance tool

$ cd /home/oracle/ogg

$ sqlplus / as sysdba;

marker_setup.sql

该脚本用于创建DDL的marker表GGS_MARKER,用于存储DDL信息,该表只进行insert操作

SQL> @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.

ddl_setup.sql

该脚本创建了进行DDL复制抽取和复制所需的对象

SQL> @ddl_setup

GoldenGate DDL Replication setup script

Verifying that current user has privileges to install DDL Replication...

Checking user sessions...

Check complete.

You will be prompted for the name of a schema for the GoldenGate database objects.

NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be enabled.

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

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 ...

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:

.....................

.....................

Analyzing installation status...

STATUS OF DDL REPLICATION

-----------------------------------------------------------------------------------

SUCCESSFUL installation of DDL Replication software components

Script complete.

role_setup.sql

创建DDL复制所需的对象

SQL> @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 <loggedUser>

where <loggedUser> is the user assigned to the GoldenGate processes.

按照上面返回的提示,执行授权操作,注意是将权限授予执行Extract/GGSCI或其它管理操作的用户,我们这里的情况看显然是ggate,执行命令如下:

SQL> GRANT GGS_GGSUSER_ROLE TO GGATE;

Grant succeeded.

ddl_enable.sql

启用DDL复制,实质上是创建触发器,用以想MARKER和HISTORY表插入DDL信息

SQL> @ddl_enable

Trigger altered.

安装性能优化工具 (可选项)

要提高DDL触发器的性能,可以通过ddl_pin脚本,该脚本会将触发器使用的包加载到内存,以此提高效率。该脚本执行时需要引用dbms_shared_pool系统包,因此在使用ddl_pin脚本前需要确保dbms_shared_pool可用。

SQL> @?/rdbms/admin/dbmspool.sql

Package created.

Grant succeeded.

View created.

Package body created.

执行ddl_pin脚本需要指定GoldenGate管理员schema名称,例如:

SQL> @ddl_pin ggate

PL/SQL procedure successfully completed.

PL/SQL procedure successfully completed.

PL/SQL procedure successfully completed.

4、配置抽取和复制进程

抽取进程配置如下

GGSCI (rac1) 44> view params eora 
extract eora 
userid ogg,password ogg 
exttrail ./dirdat/et 
rmthost 192.168.1.112, mgrport 7500 
rmttrail ./dirdat/rt
ddl  include all

table hr.*;

抽取复制配置如下

GGSCI (rac2) 17> view params pora
replicat pora
setenv(ORACLE_SID=orcl)
userid ogg, password ogg
assumetargetdefs

handlecollisions
discardfile ./dirrpt/pora.dsc, purge

ddl include all

ddlerror default ignore retryop
map hr.*, target hr.*;

源端进程状态

GGSCI (rac1) 45> info all 
Program     Status      Group       Lag at Chkpt  Time Since Chkpt 
MANAGER     RUNNING                                            
EXTRACT     RUNNING     EORA        00:00:00      00:00:00   

目标端进程状态

GGSCI (rac2) 90> info all 
Program     Status      Group       Lag at Chkpt  Time Since Chkpt 
MANAGER     RUNNING                                            
REPLICAT    RUNNING     PORA        00:00:00      00:00:00 

验证

在Source DB 上创建一张测试表:

 SQL> conn dave/dave;

Connected.

SQL> create table anqing as select *from sys.all_users;

Table created.

到Target DB上验证:

SQL> select count(1) from anqing;

  COUNT(1)

----------

       33

DDL 同步验证成功。

DDL参数语法说明 
在配置DDL复制时,需要在Extract 和Replicat 进程的配置文件里添加ddl属性。下面简要减少下这个属性的常用参数,参考至《OGG Windows and UNIX Reference Guide》,英文较简单,我也就不一字一句的翻译了。
DDL语句包含的主要语法如下:
DDL [
{INCLUDE | EXCLUDE}
[, MAPPED | UNMAPPED | OTHER | ALL]
[, OPTYPE <type>]
[, OBJTYPE ‘<type>’]
[, OBJNAME “<name>”]
[, INSTR ‘<string>’]
[, INSTRCOMMENTS ‘<comment_string>’]
]
[...]
 
{INCLUDE | EXCLUDE} 
Use INCLUDE and EXCLUDE to identify the beginning of an inclusion or exclusion clause.
(1)  An inclusion clause containsfiltering criteria that identifies the DDL that this parameter will affect.
(2)  An exclusion clause containsfiltering criteria that excludes specific DDL from this parameter.
The inclusion orexclusion clause must consist of the INCLUDE or EXCLUDE keyword followed by anyvalid combination of other options of the parameter that is being applied.
If you use EXCLUDE, you must create acorresponding INCLUDE clause.
--如果要使用Exclude,那么必须先指定include。
For example, the following is invalid:
DDL EXCLUDE OBJNAME  “hr.*” 
--这种语法是错误的。
However, you can use either of thefollowing:
DDL INCLUDE ALL,EXCLUDE OBJNAME “hr.*” 
DDL INCLUDE OBJNAME “fin.*”  EXCLUDE  “fin.ss”         --正确语法
An EXCLUDE takes priority over any INCLUDEs that contain the same criteria. You can use multipleinclusion and exclusion clauses.
[, MAPPED | UNMAPPED | OTHER | ALL] 
Use MAPPED, UNMAPPED,OTHER, and ALL to apply INCLUDE or EXCLUDE based on the DDL operation scope.
1、MAPPED applies INCLUDE or EXCLUDE to DDL operations that are of MAPPED scope. MAPPED filtering is performed beforefiltering that is specified with other DDL parameter options.
2、UNMAPPED applies INCLUDE or EXCLUDE to DDL operations that are of UNMAPPED scope.
3、OTHER applies INCLUDE or EXCLUDE to DDL operations that are of OTHER scope.
4、ALL applies INCLUDE or EXCLUDE to DDL operations of all scopes.

关于这四种scope的具体范围详见官方文档《OGG Windows and UNIX Reference Guide》
OPTYPE <type> 
Use OPTYPE toapply INCLUDE or EXCLUDE to a specific type of DDL operation, such as CREATE, ALTER,and RENAME. For <type>, use any DDL command that is valid for thedatabase.
For example, to include ALTER operations,the correct syntax is:
DDL INCLUDE OPTYPE ALTER 
OBJTYPE‘<type>’ 
Use OBJTYPE to apply INCLUDE or EXCLUDE to a specific type of database object. For <type>,use any object type that is valid for the database, such as TABLE, INDEX, and TRIGGER.For an Oracle materialized view and materialized views log, the correct typesare snapshot and snapshot log, respectively. Enclose the name of the objecttype within single quotes.
For example:
DDL INCLUDE OBJTYPE ‘INDEX’
DDL INCLUDE OBJTYPE ‘SNAPSHOT’
 
For Oracle object type USER, do not use the OBJNAME option, because OBJNAME expects “owner.object” whereas USER only has aschema.
OBJNAME“<name>” 
Use OBJNAME toapply INCLUDE or EXCLUDE to the fully qualified name of an object, for example owner.table_name.This option takes a doublequoted string as input. You can use a wildcard onlyfor the object name.
Example:
DDL INCLUDE OBJNAME “accounts.*” 
Do not use OBJNAME for the Oracle USER object,because OBJNAME expects “owner.object” whereas USER only has a schema.
When using OBJNAMEwith MAPPED in a Replicat parameter file, the value for OBJNAME must refer tothe name specified with the TARGET clause of the MAP statement. For example,given the following MAP statement, the correct value is OBJNAME “fin2.*”.
MAP fin.exp_*,TARGET fin2.*; 
In the following example, a CREATE TABLE statementexecutes like this on the source:
CREATE TABLE fin.exp_phone; 
And like this on the target:
CREATE TABLE fin2.exp_phone; 
If a target owner is not specified in the MAP statement, Replicat maps it to the database user that is specified with the USERID parameter.
For DDL that creates triggers, synonyms, and indexes, the value for OBJNAME must be the name of the base object, not the name of the trigger, synonym, or index.
For example, to include the following DDL statement, the correct value is “hr.accounts,” not “hr.insert_trig.”
CREATE TRIGGER hr.insert_trig ON hr.accounts; 
For RENAME operations,the value for OBJNAME must be the new table name. For example, to include the following DDL statement, the correct value is “hr.acct.”
ALTER TABLE hr.accounts RENAME TO acct; 
The following is an example of how tocombine DDL parameter options.
 DDL    & 
INCLUDE UNMAPPED & 
    OPTYPE alter & 
    OBJTYPE ‘table’ & 
    OBJNAME users.tab* & 
INCLUDE MAPPED OBJNAME * & 
EXCLUDE MAPPED OBJNAME temporary.tab" 


参考至: 《OGG Windows and UNIX Reference Guide》

                《OGG Installation and Setup Guide》

                http://junsansi.itpub.net/post/29894/521800

                http://blog.csdn.net/tianlesoftware/article/details/6981358
本文原创,转载请注明出处、作者

如有错误,欢迎指正

邮箱:czmcj@163.com

作者:czmmiao  文章出处:http://czmmiao.iteye.com/blog/1609823
上一篇:php内核探索之zend_execute的具体执行过程


下一篇:【IntelliJ Idea】git commit 显示 Local Changes