GoldenGate不开启支持DDL时,对新建表、增加字段的处理

背景

生产上了GoldenGate,2个基点的双向同步实现HA。目前的设置不同步DDL,这样系统升级,表结构升级时,需要配套的在OGG里做响应操作,否则数据同步失败。

1.新建表,看trandata是否增加

新建表:

create table cust.hf_ggid (id varchar2(50),ggid varchar2(50));

查看trandata:新表没有自动增加trandata。

info trandata cust.hf_ggid
GGSCI> Logging of supplemental redo log data is disabled for table CUST.HF_GGID.

新建表,无附加日志。但可以同步数据,增、改、删都可以同步。日志有告警:

WARNING OGG-00869  Oracle GoldenGate Capture for Oracle, exts01.prm:  No unique key is defined for table 'HF_GGID'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.

ps:虽然显示没有trandata,但可以修改、删除,应该是类似没有主键的情况下,对所有字段增加了trandata。

2.增加字段,看trandata是否自动更新

    alter table cust.hf_ggid add name varchar2(50);
	insert into hf_ggid values ('addColName',sys_guid(),'name'); 

经过验证:

  1. 增、删都可执行,但会忽略新增字段;如果修改新增字段,会导致备机的replicat进程abend。
  2. 备机增加对应字段后,重启replicat进程,可继续运行。但新增字段没有同步。
  3. 备机侧,重启全部进程,新增字段仍没有同步。
  4. 在主机侧,重启抽取进程,新增字段有效。
  5. 如果只重启主机抽取进程,在备机测不识别,会报错:
    ERROR OGG-01161 Oracle GoldenGate Delivery for Oracle, rept01.prm: Bad column index (5) specified for table CUST.HF_GGID, max columns = 5.
    ps:新增字段后,要重启抽取、复制进程,否则新增字段不识别。

原理:
When Extract first encounters DML on a table, it retrieves the
metadata for that table.When DDL is encountered on that table, the old metadata is invalidated. The next DML on that table is matched to the new metadata so that the target table structure always is upto-date with that of the source.
第一次DML被extract捕获时,extract进程会检索该表的元数据。
如果该表有DDL,则老的元数据失效。新的就DML与表新结构配套。
侧面说明,extract进程会检索表结构。新增字段后,没有自动从新检索表结构,新字段不会识别。重启应该出发了重新检索动作。

3.主键字段变动

实验过程不补充了,直接说结论:

  1. trandata不能自己变动,需要重做trandata。
  2. 否则,会用旧的主键去做删、改,不能保证数据一致。

4.总结

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/heroicpoem/article/details/107189181