当source/target表结构完全一致时,replicat声明assumetargetdefs即可,如果不一致,则需指定sourcedefs/targetdefs文件,其由 defgen生成;
什么时候使用defgen
1 跨数据库环境,例如从oracle到mysql
2 source/target表定义不一致
Defgen可生成sourcedef和targetdef,前者用于target后者用于source
文件头包含metadata,文件体包含表信息
The file begins with a file header that shows the version of DEFGEN, information about character sets, the database type, the locale, and internal
metadata that indicates other data properties. Following the header are the tabledefinition sections.
Each table-definition section contains a table name, record length,number of columns, and one or more column definitions
详情可参照DataTypes From Defgen [ID 966190.1]
其生命周期如下
配置
Ggsci输入edit params defgen
--格式如下
CHARSET
DEFSFILE
[{SOURCEDB | TARGETDB}
TABLE 运行 defgen paramfile dirprm/defgen.prm [reportfile dirrpt/defgen.rpt] [NOEXTATTR] [UPDATECS UTF-8] 默认DEFGEN使用本地locale写def文件,可使用defgen修改def文件字符集 defgen paramfile ./dirdef/source.def UPDATECS UTF-8 传输 默认以ASCII模式FTP到remote,如果def文件以 remote的字符集创建,则使用binary模式,避免出现不必要的换行; 例1 创建多个source-def文件 DEFSFILE C:\ggs\dirdef\sales.def USERID ogg, PASSWORD AACAAAAAAAAAAAJAUEUGODSCVGJEEIUGKJDJTFNDKEJFFFTC, & AES128 KEYNAME mykey1 TABLE ord.*; DEFSFILE C:\ggs\dirdef\admin.def USERID ogg, PASSWORD AACAAAAAAAAAAAJAUEUGODSCVGJEEIUGKJDJTFNDKEJFFFTC, & AES128 KEYNAME mykey1 TABLE hr.*; REPLICAT acctrep USERID ogg, PASSWORD AACAAAAAAAAAAAJAUEUGODSCVGJEEIUGKJDJTFNDKEJFFFTC, & AES128 KEYNAME mykey1 SOURCEDEFS c:\ggs\dirdef\sales.def MAP ord.*, TARGET ord.*; SOURCEDEFS c:\ggs\dirdef\admin.def MAP hr.*, TARGET hr.*; Def模板 使用def模板 可被新表使用避免创建额外的def文件,新表必须有相同的表结构; 否则每次加入新表,必须为之创建def 文件,然后将内容复制到master def文件,最后重启进程 对于新增的表,无须重启进程或创建新的def文件 Def指定source-def模板 Targetdef指定target-def模板 When you create a definitions file, you can specify a definitions template that reduces the need to create new definitions files when tables are added to the Oracle GoldenGate configuration after the initial startup. To use a template, all of the new tables must have identical structures, such as in a customer database where there are separate but identical tables for each customer (see “Rules for tables to be considered identical”). If you do not use a template and new tables are added after startup, you must generate a definitions file for each new table that is added to the Oracle GoldenGate configuration, then copy their contents to the existing master definitions file, and then restart the process. http://docs.oracle.com/cd/E35209_01/doc.1121/e29397.pdf 例2 创建source def文件 DEFSFILE C:\ggs\dirdef\record.def --指定输出的def文件 USERID ogg, PASSWORD AACAAAAAAAAAAAJAUEUGODSCVGJEEIUGKJDJTFNDKEJFFFTC, & --指定数据库连接信息 AES128 KEYNAME mykey1 TABLE acct.cust100, DEF custdef; --依据acct.cust100创建template,供acct下同结构的表使用 TABLE ord.*; TABLE hr.*; replicat参数引用该文件 REPLICAT acctrep USERID ogg, PASSWORD AACAAAAAAAAAAAJAUEUGODSCVGJEEIUGKJDJTFNDKEJFFFTC, & AES128 KEYNAME mykey1 SOURCEDEFS c:\ggs\dirdef\record.def MAP acct.cust*, TARGET acct.cust*, DEF custdef; MAP ord.prod, TARGET ord.prod; MAP ord.parts, TARGET ord.parts; MAP hr.emp, TARGET hr.emp; MAP hr.salary, TARGET hr.salary; 同时使用assumetargetdefs/sourcedefs REPLICAT acctrep USERID ogg, PASSWORD AACAAAAAAAAAAAJAUEUGODSCVGJEEIUGKJDJTFNDKEJFFFTC, & AES128 KEYNAME mykey1 SOURCEDEFS c:\ggs\dirdef\record.def MAP acct.cust*, TARGET acct.cust*, DEF custdef; MAP ord.prod, TARGET ord.prod; MAP ord.parts, TARGET ord.parts; MAP hr.emp, TARGET hr.emp; MAP hr.salary, TARGET hr.salary; ASSUMETARGETDEFS MAP rpt.stock, TARGET rpt.stock; [, {DEF | TARGETDEF} ]; --指定候选表,而def/targetdef据此表产生def模板