Title
Create new category
Edit page index title
Edit category
Edit link
How to Enable SQL Replication for DB2
Issue
Enabling SQL replication for DB2.
Solution
References
- To enable SQL replication is DB2, refer https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.1.0/com.ibm.swg.im.iis.db.repl.intro.doc/topics/iiyrcintrssql.html.
- To prune and support retention interval in the CD table, refer http://www-01.ibm.com/support/docview.wss?uid=swg21113839.
Note: The table on which you want to enable replication must have a unique index defined. In this case, the replication table is ABC.EMPLOYEE, and the database used is WESTERN.
The following capture program replicates the data from ABC.EMPLOYEE to ABC.CDEMPLOYEE and ABC.TGEMPLOYEE.
Follow the steps below to enable SQL replication for DB2:
Create sqlrep.asnclp script with the following content:
# Identify source table(s).# Identify databases involved.# ('Control' and 'Target' are usually the same)SET RUN SCRIPT NOW STOP ON SQL ERROR ON;SET SERVER CAPTURE TO DB WESTERN ID db2inst1 PASSWORD "IN11**rk";CREATE CONTROL TABLES FOR CAPTURE SERVER;CREATE REGISTRATION (ABC.EMPLOYEE) DIFFERENTIAL REFRESH STAGE ABC.CDEMPLOYEE;SET SERVER CONTROL TO DB WESTERN ID db2inst1 PASSWORD "IN11**rk";SET SERVER TARGET TO DB WESTERN ID db2inst1 PASSWORD "IN11**rk";# Add metadata tables to hold information about# your source and target tables.CREATE CONTROL TABLES FOR APPLY CONTROL SERVER;# Changed data will be 'staged' (stored) in a 'CD' table# A subscription maps a source table to a target table.# Subscriptions are grouped in sets.# Every subscription must be in a set, so we make a set here:CREATE SUBSCRIPTION SET SETNAME SETWESTERNTE APPLYQUAL MYQUALWESTERNTE ACTIVATE YESTIMING INTERVAL 1 START DATE "2019-05-05" TIME "01:00:00.000000";# Each subscription is a member of a set.# If needed, you can create the target table as we do here:SET PROFILE TBSPROFILETE FOR OBJECT TARGET TABLESPACE OPTIONS UW USING FILE "/opt/ibm/db2/V11.1/tablespace/TSTRGWESTERNTE.TS" SIZE 700 PAGES;CREATE MEMBER IN SETNAME SETWESTERNTE APPLYQUAL MYQUALWESTERNTE ACTIVATE YESSOURCE ABC.EMPLOYEETARGET NAME ABC.TGEMPLOYEEDEFINITION IN TSTRGWESTERNTE00 CREATE USING PROFILE TBSPROFILETETYPE USERCOPY COLS ALL REGISTERED;# Now, run the file through the asnclp command# and you are ready to replicate data.QUIT;To create the script from IBM, refer https://www.ibm.com/support/knowledgecenter/en/SSTRGZ_11.4.0/com.ibm.swg.im.iis.db.repl.asnclp.sql.doc/topics/iiyrsclpbldscriptsql.html .
After creating the script, run it using the following command:
$DB2HOME/bin/asnclp -f
This creates all the tables required for SQL replication in a separate schema called ASM. This registers the table for replication, but does not replicate the data.
After running the asnclp program, start the SQL Replication Capture (asncap) program for the database used, from a DB2 command window in the background, using the following command:
asncap capture_server=western &
Run apply program in the background using the following command:
asnapply controlserver=western apply qual=MYQUALWESTERNTE &
For more details, refer to our Knowledge Base and Best Practices!
For help, contact our support team!
(C) 2015-2022 Infoworks.io, Inc. and Confidential