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:

  • (plus)
  • (minus)
  • (multiply)
    / (divide)
    \ (remainder)
    Comparison operators:

    (greater than)
    = (greater than or equal)
    < (less than)
    <= (less than or equal)
    = (equal)
    <> (not equal)
    Results derived from comparisons can be zero (indicating FALSE) or non-zero (indicating TRUE).
    Parentheses (for grouping results in the expression)
    Conjunction operators: AND, OR
    下面是官方给出的几个例子:
    Example 1 The following calls the @COMPUTE function to extract records in which the price multiplied by the amount exceeds 10,000.
    MAP SALES.TCUSTORD, TARGET SALES.TORD,
    FILTER (@COMPUTE (PRODUCT_PRICE*PRODUCT_AMOUNT) > 10000);
    Example 2 The following uses the @STREQ function to extract records where a string is equal to ’JOE’.This example assumes that the USEANSISQLQUOTES parameter is used in the GLOBALS parameter file to apply SQL-92 rules for single and double quote marks.
    TABLE ACCT.TCUSTORD, FILTER (@STREQ ("Name", ’joe’) > 0);
    Example 3 The following selects records in which the amount column is greater than 50 and executes the filter on updates and deletes.
    TABLE ACT.TCUSTORD, FILTER (ON UPDATE, ON DELETE, AMOUNT > 50);
    Example 4 You can use the @RANGE function to divide the processing workload among multiple FILTER clauses, using separate TABLE or MAP statements. For example, the following splits the replication workload into two ranges (between two Replicat processes) based on the ID column of the source acct table.
    Note that object names are case-sensitive in this case. (Replicat group 1 parameter file)
    MAP "sales"."acct", TARGET "sales"."acct", FILTER (@RANGE (1, 2, ID));
    (Replicat group 2 parameter file)
    MAP "sales"."acct", TARGET "sales"."acct", FILTER (@RANGE (2, 2, ID));

参数2:COMPUTE
Use the @COMPUTE function to return the value of an arithmetic expression to a target column. The value returned from the function is in the form of a string.
You can omit the @COMPUTE phrase when returning the value of an arithmetic expression to another Oracle GoldenGate function, as in:
@STRNUM ((AMOUNT1 + AMOUNT2), LEFT)
The preceding returns the same result as:
@STRNUM ((@COMPUTE (AMOUNT1 + AMOUNT2), LEFT)
Arithmetic expressions can be combinations of the following elements.
Numbers
The names of columns that contain numbers
Functions that return numbers
Arithmetic operators:

  • (plus)
  • (minus)
  • (multiply)
    / (divide)
    \ (remainder)
    Comparison operators:

    (greater than)
    = (greater than or equal)
    < (less than)
    <= (less than or equal)
    = (equal)
    <> (not equal)
    Results that are derived from comparisons can be zero (indicating FALSE) or non-zero (indicating TRUE).
    Parentheses (for grouping results in the expression)
    The conjunction operators AND, OR. Oracle GoldenGate only evaluates the necessary part of a conjunction expression. Once a statement is FALSE, the rest of the expression is ignored. This can be valuable when evaluating fields that may be missing or null. For example, if the value of COL1 is 25 and the value of COL2 is 10, then the following are possible:
    @COMPUTE (COL1 > 0 AND COL2 < 3) returns 0.
    @COMPUTE (COL1 < 0 AND COL2 < 3) returns 0. COL2 < 3 is never evaluated.
    @COMPUTE ((COL1 + COL2)/5) returns 7.
    Syntax
    @COMPUTE (expression)
    expression
    A valid arithmetic expression. The numeric value plus the precision cannot be greater than 17 digits. If this limit is exceeded, @COMPUTE returns an error similar to the following.
    2013-08-01 01:54:22 ERROR OGG-01334 Error mapping data from column to column in function COMPUTE.
    Examples
    Example 1
    AMOUNT_TOTAL = @COMPUTE (AMT + AMT2)
    Example 2
    AMOUNT_TOTAL = @IF (AMT >= 0, AMT 100, 0)
    Example 3
    ANNUAL_SALARY = @COMPUTE (MONTHLY_SALARY
    12)

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同步主要以主键或者唯一键为同步基础,而此案例分表键并非主键。所以同步的时候无法以此分表键进行数据分表。

原文地址:http://blog.51cto.com/3048449/2133582

时间: 2024-08-28 10:42:42

oracle迁移到mysql分库分表方案之——ogg(goldengate)的相关文章

MySQL分库分表方案

1. MySQL分库分表方案 1.1. 问题: 1.2. 回答: 1.2.1. 最好的切分MySQL的方式就是:除非万不得已,否则不要去干它. 1.2.2. 你的SQL语句不再是声明式的(declarative) 1.2.3. 你招致了大量的网络延时 1.2.4. 你失去了SQL的许多强大能力 1.2.5. MySQL没有API保证异步查询返回顺序结果 1.2.6. 总结 MySQL分库分表方案 翻译一个stackoverflow上的问答,关于分库分表的缺点的,原文链接: MySQL shard

【分库、分表】MySQL分库分表方案

一.Mysql分库分表方案 1.为什么要分表: 当一张表的数据达到几千万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿了.分表的目的就在于此,减小数据库的负担,缩短查询时间. mysql中有一种机制是表锁定和行锁定,是为了保证数据的完整性.表锁定表示你们都不能对这张表进行操作,必须等我对表操作完才行.行锁定也一样,别的sql必须等我对这条数据操作完了,才能对这条数据进行操作. 2. mysql proxy:amoeba 做mysql集群,利用amoeba. 从上层的ja

MySQL 分库分表方案,总结的非常好!

前言 公司最近在搞服务分离,数据切分方面的东西,因为单张包裹表的数据量实在是太大,并且还在以每天60W的量增长. 之前了解过数据库的分库分表,读过几篇博文,但就只知道个模糊概念, 而且现在回想起来什么都是模模糊糊的. 今天看了一下午的数据库分库分表,看了很多文章,现在做个总结,"摘抄"下来.(但更期待后期的实操) 会从以下几个方面说起: 第一部分:实际网站发展过程中面临的问题. 第二部分:有哪几种切分方式,垂直和水平的区别和适用面. 第三部分:目前市面有的一些开源产品,技术,它们的优缺

MySQL主从(MySQL proxy Lua读写分离设置,一主多从同步配置,分库分表方案)

Mysql Proxy Lua读写分离设置 一.读写分离说明 读写分离(Read/Write Splitting),基本的原理是让主数据库处理事务性增.改.删操作(INSERT.UPDATE.DELETE),而从数据库处理SELECT查询操作.数据库复制被用来把事务性操作导致的变更同步到集群中的从数据库. 1.设置说明 Master服务器: 192.168.41.196 Slave服务器: 192.168.41.197 Proxy服务器: 192.168.41.203 2.安装Mysql Pro

OneProxy实现MySQL分库分表

OneProxy实现MySQL分库分表 简介 Part1:写在最前 随着网站的壮大,MySQL数据库架构一般会经历一个过程: 当我们数据量比较小的时候,一台单实例数据库足矣.等我们数据量增大的时候,我们会采用一主多从的数据库架构来降低我们的读写io.当我们某张业务表达到几百万上千万甚至上亿时,就应该去进行分表处理.本文演示OneProxy对数据库实现分表处理,对前端应用是透明的. Part2:环境简介 HE1:192.168.1.248 Master1 HE3:192.168.1.250 Mas

如何设计可以动态扩容缩容的分库分表方案?

对于分库分表来说,主要是面对以下问题: 选择一个数据库中间件,调研.学习.测试: 设计你的分库分表的一个方案,你要分成多少个库,每个库分成多少个表,比如 3 个库,每个库 4 个表: 基于选择好的数据库中间件,以及在测试环境建立好的分库分表的环境,然后测试一下能否正常进行分库分表的读写: 完成单库单表到分库分表的迁移,双写方案: 线上系统开始基于分库分表对外提供服务: 扩容了,扩容成 6 个库,每个库需要 12 个表,你怎么来增加更多库和表呢? 是你必须面对的一个事儿,就是你已经弄好分库分表方案

分库分布的几件小事(三)可以动态扩容缩容的分库分表方案

1.扩容与缩容 这个是你必须面对的一个事儿,就是你已经弄好分库分表方案了,然后一堆库和表都建好了,基于分库分表中间件的代码开发啥的都好了,测试都ok了,数据能均匀分布到各个库和各个表里去,而且接着你还通过双写的方案咔嚓一下上了系统,已经直接基于分库分表方案在搞了. 那么现在问题来了,你现在这些库和表又支撑不住了,要继续扩容咋办?这个可能就是说你的每个库的容量又快满了,或者是你的表数据量又太大了,也可能是你每个库的写并发太高了,你得继续扩容. 缩容就是现在业务不景气了,数据量减少,并发量下降,那么

如何设计动态扩容缩容的分库分表方案?

面试官:如何来设计动态扩容的分库分表方案?面试官心理剖析:这个问题主要是看看你们公司设计的分库分表设计方案怎么样的?你知不知道动态扩容的方案? 回答: 背景说明:如果你们公司之前已经做了分库分表,你们当时分了 4 个库,每个库 4 张表:公司业务发展的很好,现在的数据库已经开始吃力了,不能满足快速发展的业务量了,需要进行扩容. 1)停机扩容 这个方案跟单库迁移方案是一样的,就是停服进行数据迁移,不过现在的数据迁移比之前的单库迁移要复杂的多,还有数据量也是之前的好几倍,单库的数据量可能就几千万,但

浅谈-分库分表方案

名词解释 库:database:表:table:分库分表:sharding 数据库架构演变 刚开始我们只用单机数据库就够了,随后面对越来越多的请求,我们将数据库的写操作和读操作进行分离, 使用多个从库副本(Slaver Replication)负责读,使用主库(Master)负责写, 从库从主库同步更新数据,保持数据一致.架构上就是数据库主从同步. 从库可以水平扩展,所以更多的读请求不成问题. 但是当用户量级上来后,写请求越来越多,该怎么办?加一个Master是不能解决问题的, 因为数据要保存一