Required Privileges for Db2 CDC
If you only need to migrate the existing data, you can skip this article.
Enable Archive Logging for Database
Switch to the
db2inst1
user and connect to the database.su - db2inst1
db2 connect to <db_name>View the current primary log mode of the database.
- If it returns OFF, archiving mode is not enabled
db2 get db cfg for <db_name> | grep LOGARCHMETH1
Change the database log mode.
- For details, see Primary log archive method configuration parameter and Secondary log archive method configuration parameter.
- The ASN agent must have a closest starting point to read from. The following command may trim the data so that only the latest version is available. If you don't need to keep old versions of data, Please specify
dev/null
backup location.
db2 update db cfg for <db_name> using LOGARCHMETH1 <backup_path>
Disconnect other applications from the database.
db2 force applications all
After you change db2 to archive logs for the first time, the database is in
BACKUP PENDING
state and a full backup is required.db2 backup db <db_name>
Connect to the database and check whether the database is in archive logging mode.
db2 connect to <db_name>
db2 get db cfg for <db_name> | grep -i LOGARCHMETH1
Initialize Db2 ASN Capture Program
Enable the archive mode for the database. When Db2 CDC is enabled at the same time, the add/delete/change operations of the user's subscribed tables are captured by Db2 ASN Capture and written to the CDC table, and then BladePipe scans the relevant tables for incremental synchronization.
The following script allows you to initialize the Db2 ASN Capture program with one click.
# Install CDC starter tool
/bin/bash -c "$(curl -fsSL https://gitee.com/clougence/db2-cdc-tools/raw/master/script/install.sh)"
# Run the script. <db_name> Needs to be replaced with the database name
bash ./cdc_tools/cdc_setup.sh <db_name>