oracle迁移到mysql分库分表方案之——ogg(goldengate)

之前文章主要介绍了oracle 迁移到mysql,主要是原表原结构迁移,但是实际运维中会发现,到mysql以后需要分库和分表的拆分操作,这个时候,用ogg来做,也是很强大好用的。
主要结合ogg的2个参数
参数1:filter的过滤功能
官方的介绍和举例如下:
Use a FILTER clause to select rows based on a numeric value by using basic operators or one or more Oracle GoldenGate column-conversion functions.
NOTE To filter a column based on a string, use one of the Oracle GoldenGate string
functions or use a WHERE clause.
Syntax TABLE ,
, FILTER (
[, ON INSERT | ON UPDATE| ON DELETE]
[, IGNORE INSERT | IGNORE UPDATE | IGNORE DELETE]
, );
Or...
Syntax MAP
, TARGET
,
, FILTER (
[, ON INSERT | ON UPDATE| ON DELETE]
[, IGNORE INSERT | IGNORE UPDATE | IGNORE DELETE]
[, RAISEERROR ]
, );
Valid FILTER clause elements are the following:
● An Oracle GoldenGate column-conversion function. These functions are built into
Oracle GoldenGate so that you can perform tests, manipulate data, retrieve values,
and so forth. For more information about Oracle GoldenGate conversion functions, see
“Testing and transforming data” on page 158.
● Numbers
● Columns that contain numbers
● Functions that return numbers
● Arithmetic operators:

2个参数的使用方法上面介绍了,下面进行分库分表

根据某业务id(sale_prod_id)进行分库分表—— 此id非主键
源端:scott.sale_date表
目标端:多库多表:
d_sale0.sale_date
d_sale1.sale_date
d_sale2.sale_date
d_sale3.sale_date
d_sale4.sale_date
d_sale5.sale_date

抽取投递进程参考上一文章,主要改变的就是应用进程的map
map scott.sale_date,target d_sale0.sale_date,FILTER (@compute( sale_prod_id \ 5)=0);
map scott.sale_date,target d_sale1.sale_date,FILTER (@compute( sale_prod_id \ 5)=1);
map scott.sale_date,target d_sale2.sale_date,FILTER (@compute( sale_prod_id \ 5)=2);
map scott.sale_date,target d_sale3.sale_date,FILTER (@compute( sale_prod_id \ 5)=3);
map scott.sale_date,target d_sale4.sale_date,FILTER (@compute( sale_prod_id \ 5)=4);

初始化未发现任何问题,实时同步发现异常dml不同步。
最终解决方案在源端:add trandata scott.sale_date COLS(sale_prod_id)----其中sale_prod_id就是要filter的字段
大致原因是由于ogg同步主要以主键或者唯一键为同步基础,而此案例分表键并非主键。所以同步的时候无法以此分表键进行数据分表。

猜你喜欢

转载自blog.51cto.com/3048449/2133582