oracle遷移到mysql分庫分表方案之——ogg(goldengate)

來源:互聯網
上載者:User

標籤:ret   multi   replicat   oba   expr   ...   gre   RoCE   names   

之前文章主要介紹了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同步主要以主鍵或者唯一鍵為同步基礎,而此案例分表鍵並非主鍵。所以同步的時候無法以此分表鍵進行資料分表。

oracle遷移到mysql分庫分表方案之——ogg(goldengate)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.