Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
oracle_goldengate_generic_jdbc [2020/11/12 18:06] – andonovj | oracle_goldengate_generic_jdbc [2020/11/12 18:21] (current) – andonovj | ||
---|---|---|---|
Line 343: | Line 343: | ||
mysql> | mysql> | ||
</ | </ | ||
+ | |||
+ | =====Replication with Different Table Structure===== | ||
+ | What if we want to replicate between two tables which have different structure: | ||
+ | |||
+ | |||
+ | < | ||
+ | --Source: | ||
+ | SQL> desc product_prod | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | --Destination: | ||
+ | mysql> describe product_prod; | ||
+ | +-------------+---------------+------+-----+---------+-------+ | ||
+ | | Field | Type | Null | Key | Default | Extra | | ||
+ | +-------------+---------------+------+-----+---------+-------+ | ||
+ | | product_id | ||
+ | | prod_code | ||
+ | | prod_name | ||
+ | | supplier_id | decimal(10, | ||
+ | +-------------+---------------+------+-----+---------+-------+ | ||
+ | 4 rows in set (0.00 sec) | ||
+ | </ | ||
+ | |||
+ | In our case the product_id and product_code on the source are different than the prod_name and prod_code on the destination, | ||
+ | |||
+ | |||
+ | < | ||
+ | SQL> insert into product_prod select * from product where product_id < 100; | ||
+ | |||
+ | 99 rows created. | ||
+ | |||
+ | SQL> commit; | ||
+ | |||
+ | Commit complete. | ||
+ | |||
+ | SQL> | ||
+ | </ | ||
+ | |||
+ | The Golden Gate Replication Replicat will ABEND: | ||
+ | |||
+ | < | ||
+ | GGSCI (edvmr1p0) 8> info all | ||
+ | |||
+ | Program | ||
+ | |||
+ | MANAGER | ||
+ | REPLICAT | ||
+ | |||
+ | |||
+ | GGSCI (edvmr1p0) 9> view report rjdbc | ||
+ | |||
+ | ------------------------------------------------------------------------ | ||
+ | : [/ | ||
+ | g:: | ||
+ | : [/ | ||
+ | 6d]] | ||
+ | : [/ | ||
+ | : [/ | ||
+ | : [/ | ||
+ | |||
+ | 2020-11-12 18: | ||
+ | </ | ||
+ | |||
+ | |||
+ | So in order to fix that we have to do 2 things: | ||
+ | |||
+ | * Fix the jdbc properties file, to allow mapping of column with different names | ||
+ | * Map these columns in the rjdbc parameter file | ||
+ | |||
+ | So let's do it: | ||
+ | |||
+ | ====Modify JDBC Properties File==== | ||
+ | Make sure to add the following parameters, to the existing configuration. | ||
+ | |||
+ | < | ||
+ | gg.mdp.type=jdbc | ||
+ | gg.mdp.ConnectionUrl=jdbc: | ||
+ | gg.mdp.DriverClassName=com.mysql.jdbc.Driver | ||
+ | gg.mdp.UserName=oracle | ||
+ | gg.mdp.Password=< | ||
+ | </ | ||
+ | |||
+ | ====Modify Replicat Param File==== | ||
+ | Now we can modify the RJDBC param file: | ||
+ | |||
+ | < | ||
+ | [oracle@edvmr1p0 dirprm]$ trg | ||
+ | [oracle@edvmr1p0 oggtrg]$ ggsci | ||
+ | |||
+ | Oracle GoldenGate Command Interpreter | ||
+ | Version 12.2.0.1.160823 OGGCORE_OGGADP.12.2.0.1.0_PLATFORMS_161019.1437 | ||
+ | Linux, x64, 64bit (optimized), | ||
+ | Operating system character set identified as UTF-8. | ||
+ | |||
+ | Copyright (C) 1995, 2016, Oracle and/or its affiliates. All rights reserved. | ||
+ | |||
+ | |||
+ | |||
+ | GGSCI (edvmr1p0) 1> edit param rjdbc | ||
+ | |||
+ | REPLICAT rjdbc | ||
+ | TARGETDB LIBFILE libggjava.so SET property=dirprm/ | ||
+ | REPORTCOUNT EVERY 1 MINUTES, RATE | ||
+ | GROUPTRANSOPS 1000 | ||
+ | MAP OGGSRC.CUSTOMER_PROD, | ||
+ | MAP OGGSRC.PRODUCT_PROD, | ||
+ | COLMAP(USEDEFAULTS, | ||
+ | |||
+ | :wq | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====Verify the Replication==== | ||
+ | Now, we can start the RJDBC and verify if the rows were replicated: | ||
+ | |||
+ | < | ||
+ | GGSCI (edvmr1p0) 3> start rjdbc | ||
+ | |||
+ | Sending START request to MANAGER ... | ||
+ | REPLICAT RJDBC starting | ||
+ | |||
+ | |||
+ | GGSCI (edvmr1p0) 4> info all | ||
+ | |||
+ | Program | ||
+ | |||
+ | MANAGER | ||
+ | REPLICAT | ||
+ | |||
+ | |||
+ | GGSCI (edvmr1p0) 5> info all | ||
+ | |||
+ | Program | ||
+ | |||
+ | MANAGER | ||
+ | REPLICAT | ||
+ | |||
+ | GGSCI (edvmr1p0) 7> send rjdbc,stats | ||
+ | |||
+ | Sending STATS request to REPLICAT RJDBC ... | ||
+ | |||
+ | Start of Statistics at 2020-11-12 18:19:49. | ||
+ | |||
+ | Replicating from OGGSRC.PRODUCT_PROD to bigdata.product_prod: | ||
+ | |||
+ | *** Total statistics since 2020-11-12 18:19:41 *** | ||
+ | Total inserts | ||
+ | Total updates | ||
+ | Total deletes | ||
+ | Total discards | ||
+ | Total operations | ||
+ | </ | ||
+ | |||
+ | We see that 99 inserts were processed, we can check of course also the MySQL database: | ||
+ | |||
+ | < | ||
+ | mysql> select count(*) from product_prod; | ||
+ | +----------+ | ||
+ | | count(*) | | ||
+ | +----------+ | ||
+ | | 99 | | ||
+ | +----------+ | ||
+ | 1 row in set (0.00 sec) | ||
+ | |||
+ | mysql> | ||
+ | </ | ||
+ |