Enabling CDC on your Database

The Debezium framework has some DB connectors to capture data changes (CDC), but to work properly, the DB should also be properly configured.

MySQL

For that Db should be enabled binary logging.

To check it enough to execute the following query -

show master status 
or 
for AWS - show variables like 'log_bin'

If we have any records in the result, it means - bin log is enabled and Debezium will handle data changes.

Some additional info - how to configure the Amazon instance can find here

Also, it should be ROW type

Postgres

     SHOW wal_level;

if wal_level does not equal logical execute command below:

     ALTER SYSTEM SET wal_level = logical;

and restart the DB instance.

MS SQL SERVER:

SQLSERVER agent should be enabled

For the docker image use the following

$ docker exec -it --user root CONTAINER_ID /bin/sh


root@57301203bac5:/# /opt/mssql/bin/mssql-conf set sqlagent.enabled true 

SQL Server needs to be restarted in order to apply this setting. Please run 'systemctl restart mssql-server.service'. 

root@57301203bac5:/# systemctl restart mssql-server.service

Execute the following query to check whether CDC is enabled or not.

select
   name,
   is_cdc_enabled
from sys. databases
where name = '{{DB_NAME}}';

If CDC is disabled, execute the following script:

USE {{DB_NAME}};
GO

EXECUTE sys.sp_cdc_enable_db;
GO

Check in CDC enabled for the table

select name, is_tracked_by_cdc
from sys. tables
where name = 'YourTableName';

Then for EACH table execute the script provided below:

EXEC sys.sp_cdc_enable_table
    @source_schema=N'{{SCHEMA_NAME}}',
    @source_name=N'{{TABLE_NAME}}',
    @role_name = NULL,
    @supports_net_changes=0
GO

Then execute

EXEC sys.sp_cdc_add_job @job_type = N'capture';
GO

EXEC sys.sp_cdc_start_job @job_type = 'capture'
GO

Last updated