千家信息网

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

发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,之前文章主要介绍了oracle 迁移到mysql,主要是原表原结构迁移,但是实际运维中会发现,到mysql以后需要分库和分表的拆分操作,这个时候,用ogg来做,也是很强大好用的。主要结合ogg的2个参
千家信息网最后更新 2025年11月07日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就是分表的字段
大致原因是由于ogg同步主要以主键或者唯一键为同步基础,而此案例分表键并非主键。所以同步的时候无法以此分表键进行数据分表。

分表 同步 参数 分库 就是 文章 时候 进程 方案 强大 业务 使用方法 例子 原因 基础 字段 官方 实时 实际 数据 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络安全内防内控 策略 福州软件开发培训机构哪家好 软件开发工具doc下载 宝山区什么是网络技术创新服务 设置小米盒子网络安全性咋选 三国杀服务器连不上 网络安全动态防御能力指标 如何利用样本模板创建数据库 电子商务网站数据库项目知识要点 网络安全和信息化工作汇总结 软件开发模型及其要义 明辨网络安全的心得体会 河北网络技术服务哪个好 武汉大学网络安全研究生就业 池州安卓软件开发外包公司 软件开发合同金额 服务器安装虚拟机报错误代码 数据库脚本怎么写 我的世界黏土服务器举报指令 cnbs 数据库 魔兽世界三区服务器推荐 软件开发笔记图片 软件开发的机遇与挑战 美国大学网络安全发展 二道区网络技术咨询诚信服务 jdbc存入数据库代码 数据库技术你博客 服务器如何清理空间 专家谈网络安全审查 国家对网络技术的政策
0