SQL Server Connector
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Many legacy line-of-business systems run on Microsoft SQL Server. When such a database is the source of a
strangler-fig migration, the Debezium SQL Server connector is the component that turns every committed INSERT,
UPDATE and DELETE into a change event in Kafka, so that the new application and its new database can be kept in
sync while both systems run side by side. Unlike the Oracle, PostgreSQL and MySQL connectors, the SQL Server connector
does not read the transaction log itself. It relies on SQL Server’s own change data capture (CDC) feature, which
copies changes from the log into change tables, and then polls those change tables. Most of what can go wrong in a SQL
Server migration follows from that design: CDC must be enabled per database and per table, the SQL Server Agent must
run, change tables have a retention period, and a schema change needs a new capture instance.
This page explains that design from the migration point of view, shows the database-side setup in T-SQL, gives a complete connector configuration for a SQL Server copy of the Bookshop legacy schema, and lists how to verify each step. The general concepts (snapshots, signals, the change-event envelope, the JDBC sink) are explained on their own pages and linked from here.
Checked on 2026-11-09 against Debezium 3.7.1.Final, with Kafka 4.x (KRaft) and the
quay.io/debezium/connect:3.7.1.Final image, which already contains the SQL Server connector and the Microsoft JDBC
driver. Debezium 3.7 is tested against SQL Server 2017, 2019 and 2022. The T-SQL and connector configuration on this
page are derived from the official Debezium and Microsoft documentation; they were not run (a SQL Server 2022 container
needs more memory than the shared test host had available on that date).
How the SQL Server connector works
SQL Server CDC is a database feature. When it is enabled for a table, a capture job that runs under the SQL Server
Agent reads the transaction log and writes one row for every changed row into a change table in the cdc schema
(for example cdc.dbo_BOOK_CT). A cleanup job removes old rows from the change tables after a retention period.
The Debezium connector never touches the transaction log. It connects with JDBC and:
-
takes an initial snapshot of the captured tables and records their structure in its schema history topic;
-
for each change table, reads every change between the last stored maximum LSN (log sequence number) and the current maximum LSN;
-
sorts the changes by commit LSN and change LSN, so that they are replayed in the order in which they were committed;
-
emits one change event per changed row and passes the commit and change LSNs to Kafka Connect as the offset;
-
stores the new maximum LSN and starts again.
Three consequences matter for a migration:
-
Latency has two parts. A change first waits for the capture job (which by default scans the log every few seconds) and then for the connector’s own poll (
poll.interval.ms). Thesource.ts_msfield of each event still carries the commit time, so the lag is measurable. -
The change tables are a buffer with a deadline. If the connector is stopped for longer than the cleanup retention, the changes it has not read are deleted and the only safe recovery is a new snapshot. Size the retention to your longest planned or unplanned outage of the pipeline.
-
CDC captures what the change table captures. If a column is added to the source table, the existing change table does not get it. A new capture instance is needed, which is why schema changes need the procedure described in Schema changes and capture instances.
The connector is fault tolerant in the same way as the other Debezium source connectors. Offsets are committed periodically, so after a crash it resumes from the last committed LSN and may re-emit some events. Consumers must be idempotent; see Offsets, Restarts & Exactly-Once.
The Bookshop example on SQL Server
The Bookshop running example of this section uses an Oracle legacy database (see
Oracle Connector). To show the SQL Server connector with the same
domain, this page assumes that the legacy schema lives in a SQL Server database called BOOKSHOP, schema dbo, with the
same upper-case tables: BOOK, AUTHOR, CUSTOMER, ORDERS, ORDER_LINE and SUPPLIER_CATALOGUE. The connector is
called bookshop-sqlserver-source and uses topic.prefix=legacy-mssql, so its topics do not collide with the
Oracle pipeline’s legacy.* topics.
The SQL Server connector puts the database name into each topic name, so the BOOK table is published to
legacy-mssql.BOOKSHOP.dbo.BOOK. Everything downstream (the JDBC sink that fills the legacy_* mirror tables, the
Spring Boot translators of the anti-corruption layer) works exactly as described on
Worked Example: Oracle to PostgreSQL; only the
topic names and the source block of the events change.
USE BOOKSHOP;
GO
CREATE TABLE dbo.AUTHOR (
AUTHOR_ID NUMERIC(10) NOT NULL PRIMARY KEY,
FULL_NAME VARCHAR(200) NOT NULL
);
CREATE TABLE dbo.BOOK (
BOOK_ID NUMERIC(10) NOT NULL PRIMARY KEY,
ISBN VARCHAR(13) NULL,
TITLE VARCHAR(200) NOT NULL,
AUTHOR_ID NUMERIC(10) NULL,
PRICE NUMERIC(10,2) NULL,
CURRENCY CHAR(3) NULL,
PUBLISHED DATE NULL,
ACTIVE_FLG CHAR(1) NOT NULL DEFAULT 'Y',
SUPPLIER_ID NUMERIC(10) NULL,
LAST_UPD DATETIME2(3) NULL
);
CREATE TABLE dbo.CUSTOMER (
CUST_ID NUMERIC(10) NOT NULL PRIMARY KEY,
CUST_NAME VARCHAR(200) NULL,
EMAIL VARCHAR(320) NULL,
STATUS_CD CHAR(1) NOT NULL DEFAULT 'A',
CREATED_DT DATETIME2(3) NULL
);
CREATE TABLE dbo.ORDERS (
ORDER_ID NUMERIC(12) NOT NULL PRIMARY KEY,
CUST_ID NUMERIC(10) NOT NULL,
ORDER_DT DATETIME2(3) NOT NULL,
STATUS_CD VARCHAR(2) NOT NULL,
TOTAL_AMT NUMERIC(12,2) NULL
);
CREATE TABLE dbo.ORDER_LINE (
ORDER_ID NUMERIC(12) NOT NULL,
LINE_NO NUMERIC(4) NOT NULL,
BOOK_ID NUMERIC(10) NOT NULL,
QTY NUMERIC(5) NOT NULL,
UNIT_PRICE NUMERIC(10,2) NOT NULL,
CONSTRAINT PK_ORDER_LINE PRIMARY KEY (ORDER_ID, LINE_NO)
);
CREATE TABLE dbo.SUPPLIER_CATALOGUE (
SUPPLIER_ID NUMERIC(10) NOT NULL,
ISBN VARCHAR(13) NOT NULL,
SUPPLIER_PRICE NUMERIC(10,2) NULL,
FEED_TS DATETIME2(6) NULL,
CONSTRAINT PK_SUPPLIER_CATALOGUE PRIMARY KEY (SUPPLIER_ID, ISBN)
);
GO
Reference: Debezium — SQL Server data type mappings
The Oracle DATE columns become DATETIME2(3) here because SQL Server’s DATE has no time part. How each SQL Server
type is mapped to a Kafka Connect type (and how time.precision.mode and decimal.handling.mode change that) is
covered on Data Types & Precision.
Prerequisites
Before the connector can capture anything, a SQL Server administrator has to prepare the database. The official prerequisites are:
-
a SQL Server edition and version that supports CDC (the connector is based on the CDC feature available in SQL Server 2016 SP1 and later, Standard or Enterprise edition; Debezium 3.7 is tested with 2017, 2019 and 2022);
-
membership in the
sysadminfixed server role to enable CDC on the database, anddb_ownerto enable it on tables; -
a running SQL Server Agent, because the capture and cleanup jobs are Agent jobs;
-
CDC can only be enabled on user databases; it cannot be enabled on
master.
In a container lab, the Agent is enabled with the MSSQL_AGENT_ENABLED=true environment variable of the official
mcr.microsoft.com/mssql/server image. On an installed server, start the SQL Server Agent service and set it to start
automatically. A stopped Agent is the most common reason for a connector that runs but emits nothing.
Enabling CDC on the database
CDC is enabled once per database with the system stored procedure sys.sp_cdc_enable_db. It creates the cdc schema,
the cdc user, the metadata tables and the Agent jobs.
USE BOOKSHOP;
GO
EXEC sys.sp_cdc_enable_db;
GO
-- Check: is_cdc_enabled must be 1
SELECT name, is_cdc_enabled FROM sys.databases WHERE name = 'BOOKSHOP';
GO
On Amazon RDS for SQL Server the sysadmin role is not available, so the database is enabled with the RDS procedure
msdb.dbo.rds_cdc_enable_db instead (see Azure SQL and Amazon RDS for SQL Server).
Enabling CDC on the tables
CDC must then be enabled for every table that the migration needs, with sys.sp_cdc_enable_table. Each call creates
a capture instance: a change table plus the functions that read it. The parameters that matter for Debezium are:
@source_schemaand@source_name-
the table to capture.
@role_name-
the gating role. Only members of this role (and
sysadmin/db_owner) can read the change table. Create a dedicated role for the connector instead of passingNULL; withNULL, no role restricts access to the captured data. @filegroup_name-
the filegroup that holds the change table. It must already exist. The Debezium documentation recommends not putting change tables in the same filegroup as the source tables, so that change-table growth does not compete with the business data.
@supports_net_changes-
whether SQL Server also builds the "net changes" function. Debezium reads every change, not the net changes, so the official example sets it to
0. @capture_instance-
the name of the capture instance. If it is omitted, SQL Server uses
<schema>_<table>(for exampledbo_BOOK). Naming it explicitly, with a version suffix, makes the later schema-change procedure easier to follow.
USE BOOKSHOP;
GO
-- A filegroup and file for the change tables, separate from the data filegroup
ALTER DATABASE BOOKSHOP ADD FILEGROUP BOOKSHOP_CT;
ALTER DATABASE BOOKSHOP ADD FILE (NAME = 'BOOKSHOP_CT', FILENAME = '/var/opt/mssql/data/BOOKSHOP_CT.ndf')
TO FILEGROUP BOOKSHOP_CT;
GO
-- The gating role that will be granted to the Debezium login
CREATE ROLE cdc_reader;
GO
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'BOOK',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_BOOK_v1';
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'AUTHOR',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_AUTHOR_v1';
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'CUSTOMER',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_CUSTOMER_v1';
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'ORDERS',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_ORDERS_v1';
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'ORDER_LINE',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_ORDER_LINE_v1';
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'SUPPLIER_CATALOGUE',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_SUPPLIER_CATALOGUE_v1';
GO
The physical file path in ADD FILE is the default data directory of the Linux container image; on Windows or on a
managed service, use the path (or the default filegroup) that the database administrator chooses.
Indexed views (materialized views) cannot be captured, because SQL Server CDC requires the base object of a capture instance to be a table. If the legacy application keeps important data only in an indexed view, capture its base tables instead and rebuild the view in the new system.
A least-privilege connector login
The Debezium documentation examples connect as sa, which is acceptable in a lab and never in a migration that touches
production data. The connector needs:
-
SELECTon the captured columns of the source tables, for the initial and incremental snapshots; -
membership of the gating role, to read the change tables;
-
a way to check whether the SQL Server Agent is running. The connector checks the Agent when it finds no maximum LSN. The built-in query needs
VIEW SERVER STATE, which is an instance-wide permission. The alternative is to setdatabase.sqlserver.agent.status.queryto a query that calls a function you control; -
INSERTon the signaling table, if incremental snapshots are used (Debezium writes snapshot watermarks into it).
USE master;
GO
CREATE LOGIN dbz_bookshop WITH PASSWORD = 'change-me-to-a-secret', CHECK_POLICY = ON;
GO
USE BOOKSHOP;
GO
CREATE USER dbz_bookshop FOR LOGIN dbz_bookshop;
ALTER ROLE cdc_reader ADD MEMBER dbz_bookshop; -- gating role: read the change tables
GRANT SELECT ON SCHEMA::dbo TO dbz_bookshop; -- snapshots read the source tables
GO
-- Optional: let the connector check the Agent without VIEW SERVER STATE.
-- The function runs with the owner's rights (EXECUTE AS OWNER).
CREATE FUNCTION dbo.func_is_sql_server_agent_running()
RETURNS BIT
WITH EXECUTE AS OWNER
AS
BEGIN
RETURN (SELECT CASE WHEN dss.[status] = 4 THEN 1 ELSE 0 END
FROM sys.dm_server_services dss
WHERE dss.[servicename] LIKE N'SQL Server Agent (%');
END;
GO
GRANT EXECUTE ON dbo.func_is_sql_server_agent_running TO dbz_bookshop;
GO
With that function in place, the connector property becomes
database.sqlserver.agent.status.query=SELECT [#db].dbo.func_is_sql_server_agent_running(), where [#db] is the
placeholder that Debezium replaces with the database name. A function that reads sys.dm_server_services under
EXECUTE AS OWNER still needs an owner who has the permission; agree with the database administrator on how the
function is signed or owned in your environment.
Verifying access
The connector user must see every capture instance. Log in as the connector user and run
sys.sp_cdc_help_change_data_capture; if the result is empty, the user is not in the gating role or cannot read the
captured columns.
USE BOOKSHOP;
GO
EXECUTE AS LOGIN = 'dbz_bookshop';
EXEC sys.sp_cdc_help_change_data_capture;
REVERT;
GO
-- The Agent jobs that CDC created for this database
SELECT job_type, maxtrans, maxscans, continuous, pollinginterval, retention
FROM msdb.dbo.cdc_jobs
WHERE database_id = DB_ID('BOOKSHOP');
GO
Capture and cleanup job parameters
The capture job’s polling behaviour is a trade-off between latency and load on the legacy server: each scan of the log
costs CPU on a database that is still serving production traffic. The parameters live in msdb.dbo.cdc_jobs and are
changed with sys.sp_cdc_change_job. The Debezium documentation lists the three that matter most:
| Parameter | Default | Effect |
|---|---|---|
|
5 (seconds) |
Seconds the capture job waits between log scan cycles. Higher means less load and more latency; |
|
500 |
Maximum number of transactions processed in one scan cycle. Lower means less load per cycle and more latency. |
|
10 |
Maximum number of scan cycles the job runs to read the whole log before it pauses for |
The cleanup job has a retention (in minutes) that decides how long change rows stay in the change tables. For a
migration this is the more important number: it is the longest time the Debezium connector can be stopped without
losing changes. Set it explicitly, and make it longer than the longest connector outage you are prepared to recover
from without a new snapshot.
USE BOOKSHOP;
GO
-- Capture job: scan every 2 seconds, up to 1000 transactions per cycle
EXEC sys.sp_cdc_change_job @job_type = N'capture', @pollinginterval = 2, @maxtrans = 1000;
-- Cleanup job: keep change rows for 7 days (10080 minutes)
EXEC sys.sp_cdc_change_job @job_type = N'cleanup', @retention = 10080;
GO
-- Changes take effect only after the job is restarted
EXEC sys.sp_cdc_stop_job @job_type = N'capture';
EXEC sys.sp_cdc_start_job @job_type = N'capture';
GO
Reference: Debezium — SQL Server capture job agent configuration parameters and Microsoft — sys.sp_cdc_change_job
Longer retention means larger change tables, which is why the change tables belong in their own filegroup. Watch its size during the first weeks of the migration.
Connector configuration
The following configuration captures the Bookshop tables from the BOOKSHOP database. It uses the dedicated login, a
truststore for the encrypted connection, the Agent-status function, a signal table and the canonical heartbeat
setting. Credentials are read from a file by the Kafka Connect FileConfigProvider rather than written in the JSON; see
Security & Data Protection.
{
"name": "bookshop-sqlserver-source",
"config": {
"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector",
"tasks.max": "1",
"database.hostname": "sqlserver",
"database.port": "1433",
"database.user": "dbz_bookshop",
"database.password": "${file:/opt/kafka/secrets/sqlserver.properties:password}",
"database.names": "BOOKSHOP",
"topic.prefix": "legacy-mssql",
"table.include.list": "dbo.BOOK,dbo.AUTHOR,dbo.CUSTOMER,dbo.ORDERS,dbo.ORDER_LINE,dbo.SUPPLIER_CATALOGUE,dbo.DEBEZIUM_SIGNAL",
"database.sqlserver.agent.status.query": "SELECT [#db].dbo.func_is_sql_server_agent_running()",
"driver.encrypt": "true",
"driver.trustServerCertificate": "false",
"driver.trustStore": "/opt/kafka/secrets/sqlserver-truststore.jks",
"driver.trustStorePassword": "${file:/opt/kafka/secrets/sqlserver.properties:truststore.password}",
"snapshot.mode": "initial",
"snapshot.isolation.mode": "snapshot",
"schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
"schema.history.internal.kafka.topic": "legacy-mssql.schema-history",
"include.schema.changes": "true",
"signal.data.collection": "BOOKSHOP.dbo.DEBEZIUM_SIGNAL",
"heartbeat.interval.ms": "10000",
"decimal.handling.mode": "precise",
"time.precision.mode": "adaptive",
"tombstones.on.delete": "true",
"custom.metric.tags": "pipeline=bookshop,role=legacy-source"
}
}
Reference: Debezium — SQL Server connector properties
The ${file:...} placeholders need the worker to be started with
config.providers=file and config.providers.file.class=org.apache.kafka.common.config.provider.FileConfigProvider.
Register the connector with the Kafka Connect REST API and check its status:
curl -s -X POST -H 'Content-Type: application/json' \
--data @bookshop-sqlserver-source.json http://localhost:8083/connectors
curl -s http://localhost:8083/connectors/bookshop-sqlserver-source/status
The properties that deserve an explanation in a migration:
| Property | Default | Why it matters in a migration |
|---|---|---|
|
none |
Comma-separated list of databases to capture. One connector can capture several legacy databases of the same instance; see Capturing several databases. |
|
none |
Namespace of every topic and schema name. Never change it after the first start: the connector would write to new topics and could not recover its schema history. |
|
all non-system tables |
Regular expressions matched against |
|
|
How the initial snapshot reads and locks; see the next section. Only |
|
built-in query |
Custom query that tells the connector whether the Agent runs, avoiding |
|
|
|
|
500 |
How long the connector waits before it checks the change tables again. Values above 5000 ms are capped at 5000 ms, and heartbeats can only be emitted once per polling cycle. |
|
0 (off) |
Emits heartbeat records to |
|
|
Also publishes schema change events to a topic named after |
|
|
|
|
0 (off) |
Upper limit on the number of captured tables, a safety net against a too-broad include list on a large legacy schema. |
Snapshots and isolation modes
When the connector starts with snapshot.mode=initial and no offsets, it reads the current maximum LSN, captures the
structure of the tables, reads every row as a r (read) event at that LSN, and then streams from the same LSN, so no
change is lost between the two phases. The snapshot modes are the same family as for the other relational connectors
(always, initial, initial_only, no_data, recovery, when_needed, when_needed_no_data,
configuration_based, custom); schema_only is deprecated in favour of no_data. Choosing between them is explained
on Initial Snapshots.
What is specific to SQL Server is snapshot.isolation.mode, which decides the transaction isolation level of the
snapshot and how long tables are locked:
| Value | Behaviour |
|---|---|
|
No locks and no consistency guarantee at all: data can be lost or corrupted. Do not use it for a migration. |
|
Does not block writers. A row changed during the snapshot can appear twice (once in the snapshot, once in the stream), which an upsert-based sink tolerates. |
|
Prevents concurrent updates of rows already read. Duplicates are still possible, as with |
|
Uses SQL Server snapshot isolation. Does not block writers and, with |
|
Repeatable read plus an exclusive lock on every captured table for the whole snapshot. Consistent but blocks the legacy application. |
For a legacy database that must stay online, snapshot is usually the right choice. It requires the database option to
be switched on first:
ALTER DATABASE BOOKSHOP SET ALLOW_SNAPSHOT_ISOLATION ON;
GO
SELECT name, snapshot_isolation_state_desc FROM sys.databases WHERE name = 'BOOKSHOP';
GO
Reference: Debezium — snapshot.isolation.mode
Large tables can be snapshotted in parallel with snapshot.max.threads (chunk-based parallel snapshots split each
table by primary-key ranges), and tables that were added later can be back-filled with an incremental snapshot without
stopping the stream; see Incremental & Blocking Snapshots.
Topics and the schema history topic
The connector writes the events of each captured table to its own topic, named
<topic.prefix>.<databaseName>.<schemaName>.<tableName>:
| Table | Topic |
|---|---|
|
|
|
|
|
|
schema change events |
|
transaction metadata (if |
|
heartbeats |
|
Like the MySQL, Oracle and Db2 connectors, the SQL Server connector keeps an internal schema history topic
(schema.history.internal.kafka.topic). It records the structure of the tables, taken from the change tables, so that
each event can be built with the schema that was in effect when the change happened, including after a restart. The
topic is for the connector only; consumers must not read it. It must have a single partition and infinite retention,
and losing it means running the connector with snapshot.mode=recovery to rebuild it. Both topics are explained in
Handling Schema Changes.
By default the initial snapshot records the schema of every table in capture mode, not just the included ones. That
makes it possible to add a table to table.include.list later without a schema error. If you set
schema.history.internal.store.only.captured.tables.ddl=true to keep the topic small, adding a table later needs a
schema snapshot first.
The change events
The events follow the standard Debezium envelope (before, after, source, op, ts_ms), described on
Anatomy of a Change Event. The SQL Server source block carries the
database, schema and table, and three position fields:
-
change_lsn: the LSN of the individual change; -
commit_lsn: the LSN of the commit of the transaction; -
event_serial_no: distinguishes several events with the same commit and change LSN (an update is stored by CDC as a "before" and an "after" row).
{
"before": {
"BOOK_ID": "A+k=", "ISBN": "9780000000011", "TITLE": "The Legacy Years",
"AUTHOR_ID": "AfU=", "PRICE": "Aq8=", "CURRENCY": "EUR",
"PUBLISHED": 18262, "ACTIVE_FLG": "Y", "SUPPLIER_ID": "Bw==",
"LAST_UPD": 1762680000000
},
"after": {
"BOOK_ID": "A+k=", "ISBN": "9780000000011", "TITLE": "The Legacy Years",
"AUTHOR_ID": "AfU=", "PRICE": "AvM=", "CURRENCY": "EUR",
"PUBLISHED": 18262, "ACTIVE_FLG": "Y", "SUPPLIER_ID": "Bw==",
"LAST_UPD": 1762680600000
},
"source": {
"version": "3.7.1.Final",
"connector": "sqlserver",
"name": "legacy-mssql",
"ts_ms": 1762680600000,
"snapshot": "false",
"db": "BOOKSHOP",
"schema": "dbo",
"table": "BOOK",
"change_lsn": "00000027:00000ac0:0002",
"commit_lsn": "00000027:00000ac0:0007",
"event_serial_no": "2"
},
"op": "u",
"ts_ms": 1762680602113,
"transaction": null
}
Reference: Debezium — SQL Server update events
Two things in this example need attention downstream. PRICE is a NUMERIC(10,2), so with
decimal.handling.mode=precise it is encoded as the bytes of an unscaled integer (AvM= is 755, which with scale 2 is
7.55). NUMERIC(10) keys are not integers either: they arrive as decimals encoded the same way (A+k= is 1001,
AfU= is 501 and Bw== is 7), which is why the
Data Types & Precision page recommends converting them before
they reach a bigint column. A delete produces a d event with after null, followed by a tombstone when
tombstones.on.delete=true.
Schema changes and capture instances
A schema change is where SQL Server differs most from the other connectors. When a column is added to dbo.BOOK, the
existing change table cdc.dbo_BOOK_v1_CT keeps its old structure, so the connector keeps emitting events without
the new column. Debezium cannot update capture tables; a database operator with elevated privileges has to create a new
capture instance. SQL Server allows two capture instances per table, and the connector switches from the old one to the
new one at the LSN where the new one starts.
The official documentation describes two procedures:
-
Online schema update. Apply the DDL, create the new capture instance, wait until Debezium streams from it, then drop the old one. There is no downtime, but changes made between the DDL and the creation of the new instance are captured with the old structure (the new column is missing from those events).
-
Offline schema update. Suspend the legacy application, wait for the connector to drain all changes, stop the connector, apply the DDL, create the new capture instance, resume the application, start the connector, and then drop the old instance. This is the safest option but needs a maintenance window.
USE BOOKSHOP;
GO
-- 1. Apply all DDL for the table in one batch
ALTER TABLE dbo.BOOK ADD FORMAT_CD CHAR(2) NULL;
GO
-- 2. Create a second capture instance with the new structure
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'BOOK',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT',
@supports_net_changes = 0, @capture_instance = N'dbo_BOOK_v2';
GO
-- 3. Only after Debezium streams from dbo_BOOK_v2 (check the connector log or notification):
EXEC sys.sp_cdc_disable_table @source_schema = N'dbo', @source_name = N'BOOK',
@capture_instance = N'dbo_BOOK_v1';
GO
Reference: Debezium — Online schema updates
Rules that come from the official page and that a migration plan must respect:
-
finish the whole procedure for one table before starting another schema change on the same table, and put all the DDL for a table in one batch so that the procedure runs once;
-
SQL Server does not allow some changes on CDC-enabled tables, such as renaming a column or changing a column type;
-
after changing a column from
NULLtoNOT NULL(or the reverse), the events keep the old optionality until a new capture instance exists; -
after
sp_renameof a table, events keep the old table name until the connector restarts.
How the new column then flows to the JDBC sink and to the anti-corruption layer, and how to sequence it with the expand/contract pattern, is covered on Handling Schema Changes and Schema Evolution Best Practices.
Capturing several databases
Legacy SQL Server estates often spread one application over several databases of the same instance (for example
BOOKSHOP and BOOKSHOP_ARCHIVE). One connector can capture them all with database.names. Each database must have CDC
enabled, and tasks.max can be raised up to the number of databases so that the connector reads them in parallel.
{
"name": "bookshop-sqlserver-multi-source",
"config": {
"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector",
"tasks.max": "2",
"database.hostname": "sqlserver",
"database.port": "1433",
"database.user": "dbz_bookshop",
"database.password": "${file:/opt/kafka/secrets/sqlserver.properties:password}",
"database.names": "BOOKSHOP,BOOKSHOP_ARCHIVE",
"topic.prefix": "legacy-mssql",
"table.include.list": "dbo.BOOK,dbo.ORDERS,dbo.ORDER_LINE,dbo.DEBEZIUM_SIGNAL",
"signal.data.collection": "BOOKSHOP.dbo.DEBEZIUM_SIGNAL,BOOKSHOP_ARCHIVE.dbo.DEBEZIUM_SIGNAL",
"driver.encrypt": "true",
"driver.trustStore": "/opt/kafka/secrets/sqlserver-truststore.jks",
"driver.trustStorePassword": "${file:/opt/kafka/secrets/sqlserver.properties:truststore.password}",
"schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
"schema.history.internal.kafka.topic": "legacy-mssql.schema-history"
}
}
Reference: Debezium — database.names and signal.data.collection
Because the database name is part of every topic name, the two databases produce separate topics
(legacy-mssql.BOOKSHOP.dbo.ORDERS and legacy-mssql.BOOKSHOP_ARCHIVE.dbo.ORDERS). With more than one task, give each
database its own signal table, as above; the official page marks support for several signal tables as a Technology
Preview in the Red Hat build.
Signals and incremental snapshots
Ad hoc snapshots (to back-fill a table added to the migration, or to repair a mirror table) are requested through a
signal. With the source channel, the signal is an INSERT into a signal table. On SQL Server, as on Db2, the signal
table must itself be enabled for CDC, because the connector only sees what the change tables contain.
USE BOOKSHOP;
GO
CREATE TABLE dbo.DEBEZIUM_SIGNAL (
id VARCHAR(42) PRIMARY KEY,
type VARCHAR(32) NOT NULL,
data VARCHAR(2048) NULL
);
GO
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'DEBEZIUM_SIGNAL',
@role_name = N'cdc_reader', @filegroup_name = N'BOOKSHOP_CT', @supports_net_changes = 0;
GRANT INSERT ON dbo.DEBEZIUM_SIGNAL TO dbz_bookshop; -- watermarks of incremental snapshots
GO
INSERT INTO BOOKSHOP.dbo.DEBEZIUM_SIGNAL (id, type, data)
VALUES ('backfill-book-1', 'execute-snapshot',
'{"data-collections": ["BOOKSHOP.dbo.BOOK"], "type": "incremental"}');
GO
Reference: Debezium — SQL Server: triggering an incremental snapshot and Debezium — Enabling the source signaling channel
The data collection names in a signal are case-sensitive and fully qualified (database.schema.table). The other
channels (Kafka, JMX, file) and the notifications that report snapshot progress are covered on
Signaling & Notifications.
Always On availability groups
The connector can read from an Always On read-only replica, which keeps the polling load off the primary of a busy
legacy system. CDC must be configured on the primary (SQL Server does not support CDC on replicas), and the connector
must set driver.applicationIntent=ReadOnly. When Debezium sees that option, it forces snapshot.isolation.mode to
snapshot (the only mode supported on read-only replicas) and commits the read-only transaction on every streaming
loop, so that it sees the latest CDC data.
{
"database.hostname": "bookshop-ag-listener",
"database.port": "1433",
"driver.applicationIntent": "ReadOnly"
}
Reference: Debezium — SQL Server Always On
Replication lag between the primary and the secondary adds to the event latency; include it in the lag budget of the migration.
Encrypted connections
The Microsoft JDBC driver encrypts connections by default. The connector configuration passes driver options through
with the driver. prefix. In production, validate the server certificate against a truststore
(driver.trustServerCertificate=false, driver.trustStore, driver.trustStorePassword), as in the configuration above.
In a local lab with a self-signed certificate you can set driver.trustServerCertificate=true; the official page warns
that this skips certificate-chain and host-name validation and must not be used in production. Setting
driver.encrypt=false disables encryption for servers that do not use TLS.
{
"driver.encrypt": "true",
"driver.trustServerCertificate": "true"
}
Reference: Debezium — Encrypting connections
Azure SQL and Amazon RDS for SQL Server
Many "legacy" SQL Server databases have already been lifted to a managed service. The connector works with them, with these differences:
| Service | What changes |
|---|---|
Azure SQL Database |
Enable CDC on the database and tables with the same procedures ( |
Azure SQL Managed Instance |
Behaves like an installed SQL Server with the Agent available; the same T-SQL applies. |
Amazon RDS for SQL Server |
|
EXEC msdb.dbo.rds_cdc_enable_db 'BOOKSHOP';
GO
USE BOOKSHOP;
GO
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'BOOK',
@role_name = N'cdc_reader', @supports_net_changes = 0;
GO
Reference: AWS — Using change data capture for Amazon RDS for SQL Server and Debezium — SQL Server on Azure and Microsoft — CDC with Azure SQL Database
Managed Kafka and managed connector runtimes are compared on Cloud Databases & Managed Kafka.
Monitoring
The connector exposes snapshot, streaming and schema history metrics through JMX (how to scrape them is on Monitoring, Logging & Tracing). For a SQL Server migration, watch at least:
-
MilliSecondsBehindSource(and its P95/P99 variants): the end-to-end lag, which includes the capture job’s polling; -
MilliSecondsSinceLastEventtogether with heartbeats: a quiet table and a stopped Agent look the same without them; -
Connected: whether the connector currently has a database connection; -
NumberOfCommittedTransactionsandSourceEventPosition: whether the LSN keeps moving; -
QueueRemainingCapacity: back pressure from Kafka.
Because the default MBean names depend on topic.prefix, the configuration above sets custom.metric.tags, so that
dashboards keep working even if the MBean name changes. On the database side, watch the size of the change-table
filegroup and the CDC log scan sessions (sys.dm_cdc_log_scan_sessions) to see whether the capture job keeps up.
When things go wrong
| Symptom | Cause | What to do |
|---|---|---|
Log says |
The Agent is stopped, so the capture job does not fill the change tables. |
Start the Agent. If the connector cannot check the Agent status, grant |
Connector runs but a table produces no events |
CDC is not enabled for the table, the connector user is not in its gating role, or the table is not in
|
Run |
New column missing from events after a DDL change |
The capture instance still has the old structure. |
Create a new capture instance (online or offline procedure), then drop the old one. |
Changes missing after a long outage |
The cleanup job removed change rows the connector had not read. |
Re-snapshot the affected tables (incremental snapshot, or a new connector with a new name); raise the cleanup
|
Connector fails with a schema history error after adding a table |
The table’s schema is not in the schema history topic (for example with |
Run a schema snapshot or an initial snapshot for the table, as described in the official procedure. |
Duplicate events after a crash or rebalance |
Offsets are committed periodically, not per event. |
Expected (at-least-once). Make sinks and consumers idempotent. |
Events go to new topics after a configuration change |
|
Restore the old value. Never change it on a running pipeline. |
Most of these failures are easier to recover from when the pipeline has been rehearsed; see Troubleshooting & Failure Recovery.
Verification checklist
Before you rely on a SQL Server source in a migration, check that:
-
sys.databases.is_cdc_enabledis1for every captured database and the Agent (or the Azure scheduler) runs; -
sys.sp_cdc_help_change_data_capture, run as the connector user, lists one capture instance for every table in the include list, including the signal table; -
the cleanup
retentioninmsdb.dbo.cdc_jobsis longer than the outage you are prepared to absorb; -
the connector status is
RUNNINGfor the connector and every task, and the snapshot completed (snapshot metrics or the snapshot notification); -
an
UPDATEof oneBOOKrow reacheslegacy-mssql.BOOKSHOP.dbo.BOOKwithin the agreed latency, and aDELETEproduces adevent and a tombstone; -
row counts and checksums of the source tables match the mirror tables (Verification & Reconciliation).
References
The T-SQL and connector configuration on this page were derived from the official documentation listed above and were not run.