Prerequisites
IBM InfoSphere Data Replication License required
The connector requires the use of the abstract syntax notation (ASN) libraries, which are available as a standard part of Db2 for Linux. To use the ASN libraries, you must have a license for IBM InfoSphere Data Replication (IIDR). You do not have to install IIDR to use the ASN libraries.- Db2 version ≥ 11.5
db2inst1
user credentials
Db2 Setup
The Connector is based on the ASN Capture/Apply agents that enable SQL Replication in Db2. A capture agent:- Generates change-data tables for tables that are in capture mode.
- Monitors tables in capture mode and stores change events for updates to those tables in their corresponding change-data tables.
Granting Privileges
It’s recommended to create a separate user and role for Streamkap to access your Db2 database. Below is an example script that does that.Enable Snapshots
You will need to create the table in the source database and give permissions to theSTREAMKAP_USER
. Streamkap will use this table for managing snapshots.
Please create the signal table with the name
STREAMKAP_SIGNAL
. It will not be recognised if given another nameEnable Change Data Capture
To put tables into capture mode, Debezium provides a set of user-defined functions (UDFs) for your convenience. The procedure here shows how to install and run these management UDFs. Alternatively, you can run Db2 control commands to put tables into capture mode. The administrator must then enable CDC for each table that you want Streamkap to capture.Prerequisites
- You are logged in to Db2 as the
db2inst1
user - On the Db2 host, the Debezium management UDFs are available in the
$HOME/asncdctools/src
directory. UDFs are available from the Debezium examples repository - The Db2 command
bldrtn
is onPATH
, e.g. by runningexport PATH=$PATH:/opt/ibm/db2/V11.5.0.0/samples/c/
with Db2 11.5
bldrtn
command provided with Db2:
dev/null
for the backup location.
db2inst1
user so the UDFs should be installed on the db2inst1
user. Copy the Debezium management UDFs and set permissions for them:
VALUE
statement to invoke them. For other UDFs, use the SQL CALL
statement. Start the ASN agent:
STREAMKAP_USER
privileges on the ASN CDC tables:
Streamkap Setup
- Go to Sources, click Add and choose Db2
-
Input the following information:
- Name for your Connector
- Hostname - IP address or hostname of the Db2 database server
- Port (default:
50000
) - Port number of the Db2 database server - Username - Name of the Db2 database user for connecting to the Db2 database server
- Password - Password to use when connecting to the Db2 database server
- Database Name - The name of the Db2 database from which to stream the changes
- Signal Table Schema - Streamkap will use a collection in this schema to manage snapshots e.g.
public
. See Enable Snapshots for more information - Connect via SSH Tunnel. See SSH Tunnel
- Add Schemas/Tables. Can also bulk upload here. The format is a simple list of each schema or table per row saved in csv format without a header.
- Click Save
Db2 Schema Evolution
While the Connector can capture schema changes, to update a schema, you must collaborate with a database administrator to ensure that the connector continues to produce change events. This is required because of how Db2 implements replication. For each table in capture mode, the replication feature in Db2 creates a change-data table that contains all changes to that source table. However, change-data table schemas are static. If you update the schema for a table in capture mode then you must also update the schema of its corresponding change-data table. The Connector cannot do this. A database administrator with elevated privileges must update schemas for tables that are in capture mode.Refresh change table structure (Online)
Online refresh limitation
In the interval between the source table structure changing in the source database, and _before _the change table structure is refreshed, change events continue to be captured with the outdated table structure.For example, if you added a new column to a source table, change events that are captured before the change table is refreshed will not contain the new column.If this cannot be tolerated, an Offline refresh has to be performed. However, that means downtime for whatever system made structural changes to your tables and your Streamkap pipelines.Please contact us for assistance if an Offline refresh is required.Procedure when adding a column to the end of a table
- Lock the source tables whose schema you want to change
- In the ASN register table, mark the locked tables as
INACTIVE
- Reinitialize the ASN capture service
- Apply all changes to the schemas for the source tables
- Apply all changes to the schemas for the corresponding change-data tables
- In the ASN register table, mark the source tables as
ACTIVE
- Reinitialize the ASN capture service
- Restart the connector to see updated column names in change events
Procedure when adding a column to the middle of a table
- Lock the source table(s) to be changed
-
In the ASN register table, mark the locked tables as
INACTIVE
- Reinitialize the ASN capture service
-
For each source table to be changed:
- Export the data in the source table
- Truncate the source table
- Alter the source table and add the column
- Load the exported data into the altered source table
- Export the data in the source table’s corresponding change-data table
- Truncate the change-data table
- Alter the change-data table and add the column
- Load the exported data into the altered change-data table
-
In the ASN register table, mark the tables as
INACTIVE
. This marks the old change-data tables as inactive, which allows the data in them to remain but they are no longer updated - Reinitialize the ASN capture service
- Restart the connector to see updated column names in change events
Reference
Debezium Management UDFs and Db2 ASN replication
If you followed our Db2 (Generic) - Enable Change Data Capture guide you can use these Debezium management UDFs to control Db2 replication (ASN) with SQL commands.Description | Command and notes |
---|---|
Start the ASN agent | VALUES ASNCDC.ASNCDCSERVICES('start','asncdc'); |
Stop the ASN agent | VALUES ASNCDC.ASNCDCSERVICES('stop','asncdc'); |
Check the status of the ASN agent | VALUES ASNCDC.ASNCDCSERVICES('status','asncdc'); |
Enable change data capture mode on a table | CALL ASNCDC.ADDTABLE('{SCHEMA}', '{TABLE}'); Replace {SCHEMA} with the name of the schema that contains the table you want to put into capture mode. Likewise, replace {TABLE} with the name of the table to put into capture mode. |
Disable change data capture mode on a table | CALL ASNCDC.REMOVETABLE('{SCHEMA}', '{TABLE}'); |
Reinitialize the ASN capture service | VALUES ASNCDC.ASNCDCSERVICES('reinit','asncdc'); Do this after you put a table into capture mode or after you remove a table from capture mode. |