Getting Started: Your First Change Events
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Every later page in this section assumes one picture in the reader’s head: a database commits a change, a Debezium connector running inside Kafka Connect reads that change from the database log, and a Kafka topic receives one event that describes it. This page builds that picture with real software in a few minutes. It is the official Debezium Kafka Connect tutorial, rebuilt as a single Docker Compose file and pinned to the 3.7.1.Final images, followed by the same lab against PostgreSQL.
The tutorial uses the small inventory sample database that Debezium ships in its example images, not the Bookshop
schema of the rest of the section. That is on purpose: the goal here is to see the mechanics (snapshot, streaming,
offsets, restarts) with nothing else in the way. Once those mechanics are familiar, the same steps apply to the legacy
Bookshop Oracle database in Oracle Connector and
Worked Example: Oracle to PostgreSQL.
Why this matters for a migration: during a strangler-fig migration (see Migration Path: From a Legacy Stack to a Modern One) the new system depends on three guarantees that this lab lets you observe directly:
-
the existing rows are copied once, as
r(read) events, before streaming starts; -
every committed insert, update and delete after that appears as a
c,uordevent, in commit order per row; -
if the capture process stops, it resumes from the exact log position it had reached, so changes made while it was down are delivered late but not lost.
Checked on 2026-11-09 against Debezium 3.7.1.Final, with Kafka 4.3.1 (KRaft mode, bundled in the Debezium images),
MySQL 8.2.0 (example-mysql) and PostgreSQL 18.6 (example-postgres). The Compose stack, both connector
configurations and every command on this page were run with Docker on 2026-11-09, and the event output shown is the
real output of that run, trimmed for width. The page uses the standard host ports (9092, 8083, 3306 and 5432).
What you build
The stack has four containers on one Docker network, plus short-lived client containers that you start when you need them.
The roles are the same as in a production migration pipeline (see Debezium Architecture):
-
Kafka stores the change-event topics and the three internal Kafka Connect topics (connector configurations, source offsets and connector status).
-
Kafka Connect runs the Debezium connector plugins. You never start a connector process yourself: you send a JSON configuration to the Connect REST API, and Connect starts the connector and its task.
-
The source databases are preconfigured for change data capture. The MySQL image has the binlog enabled in
ROWformat with full row images and adebeziumuser with replication privileges. The PostgreSQL image runs withwal_level=logical.
Prerequisites
-
Docker Engine or Docker Desktop with the Compose plugin (
docker compose versionprints v2.x). -
About 3 GB of free memory for the containers. Without a heap limit, the Kafka Connect container can be killed by the out-of-memory killer on a machine with little free memory, so the Compose file below caps its heap (the
HEAP_OPTSline). Ifdocker compose psshowsconnectasExited (137), give Docker more memory or stop other containers. -
curlandjqon the host.jqis only used to pretty-print and trim JSON. -
Free host ports 9092, 8083, 3306 and 5432. If one is taken, change only the left-hand side of the matching
portsentry and use that port in the commands.
Step 1: Start the services
The official tutorial starts Kafka, MySQL and Kafka Connect with one docker run command each, in separate terminals.
The Compose file below starts the same containers with the same environment variables in one step, and adds the
PostgreSQL example database used in the second half of the page.
name: dbz-tutorial
services:
kafka:
image: quay.io/debezium/kafka:3.7.1.Final
hostname: kafka
ports:
- "9092:9094"
environment:
CLUSTER_ID: 5Yr1SIgYQz-b-dgRabWx4g
NODE_ID: "1"
NODE_ROLE: combined
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
KAFKA_LISTENERS: PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093,EXTERNAL://0.0.0.0:9094
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT
mysql:
image: quay.io/debezium/example-mysql:3.7.1.Final
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: debezium
MYSQL_USER: mysqluser
MYSQL_PASSWORD: mysqlpw
postgres:
image: quay.io/debezium/example-postgres:3.7.1.Final
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
connect:
image: quay.io/debezium/connect:3.7.1.Final
ports:
- "8083:8083"
depends_on:
- kafka
- mysql
- postgres
environment:
GROUP_ID: "1"
BOOTSTRAP_SERVERS: kafka:9092
CONFIG_STORAGE_TOPIC: my_connect_configs
OFFSET_STORAGE_TOPIC: my_connect_offsets
STATUS_STORAGE_TOPIC: my_connect_statuses
HEAP_OPTS: -Xms256m -Xmx512m
Reference: Debezium — Tutorial: Starting the services
What each part does, and where it differs from the official docker run commands:
kafka-
A single Kafka 4.x node in KRaft mode (no ZooKeeper) that is both broker and controller (
NODE_ROLE: combined).CLUSTER_ID,NODE_ID,NODE_ROLE,KAFKA_CONTROLLER_QUORUM_VOTERS,KAFKA_LISTENERSandKAFKA_ADVERTISED_LISTENERSare the variables from the official Starting Kafka step. The cluster ID is any 22-character base64 UUID; generate your own withdocker run --rm quay.io/debezium/kafka:3.7.1.Final /kafka/bin/kafka-storage.sh random-uuidif you prefer. The image’s entry point turns everyKAFKA_*variable into aserver.propertiesentry, formats the storage directory on first start, and prints a warning thatKAFKA_CONTROLLER_QUORUM_VOTERSis deprecated since Kafka 4.1.1. It converts the value tocontroller.quorum.bootstrap.serversitself, so the warning is harmless here.
The official command advertises onlykafka:9092, which works for clients inside the Docker network but not for a client on the host. This file adds a third listener,EXTERNAL, that listens on container port 9094, is published as host port 9092 and advertiseslocalhost:9092. Containers keep usingkafka:9092; host tools such as a localkcator a Spring Boot application started from the IDE uselocalhost:9092. mysql-
The
example-mysqlimage (based on MySQL 8.2) with theinventorysample database. The variables are those of the official Starting a MySQL database step. The image also creates thedebeziumuser (passworddbz) that the connector uses. postgres-
The
example-postgresimage (PostgreSQL 18 withwal_level=logical) with the sameinventorydata in a schema calledinventory. It is only needed for the second half of the page. connect-
Kafka Connect with every Debezium connector plugin already installed.
GROUP_ID,BOOTSTRAP_SERVERSand the three*_STORAGE_TOPICvariables are those of the official Starting Kafka Connect step. The storage topics are where Kafka Connect keeps connector configurations, source offsets and status, which is why connectors survive a restart of the Connect container.HEAP_OPTScaps the JVM heap so that the stack fits on a laptop. Compose service names resolve as host names on the project network, so the--linkoptions of the official commands are not needed.
Start the stack and wait until Kafka Connect answers:
docker compose up -d
# Repeat until it answers (Kafka Connect needs 20-60 seconds to scan its plugins)
curl -s -H "Accept:application/json" localhost:8083/ | jq .
Reference: Debezium — Tutorial: Starting Kafka Connect
{
"version": "4.3.1",
"commit": "26b251a451ce941d",
"kafka_cluster_id": "5Yr1SIgYQz-b-dgRabWx4g"
}
The version is the Kafka Connect version, not the Debezium version. To see which Debezium plugins the worker loaded,
and their versions, list the connector plugins:
curl -s localhost:8083/connector-plugins | jq -c '.[] | select(.type == "source")'
Reference: Apache Kafka 4.3 — Kafka Connect REST API
{"class":"io.debezium.connector.mariadb.MariaDbConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.mongodb.MongoDbConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.mysql.MySqlConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.oracle.OracleConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.postgresql.PostgresConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.sqlserver.SqlServerConnector","type":"source","version":"3.7.1.Final"}
The full list also contains the Db2, Informix, Spanner, Vitess, CockroachDB and Db2 for IBM i source connectors, the JDBC and MongoDB sink connectors, and the Kafka MirrorMaker connectors. Some of those Debezium connectors are incubating; see Db2, Informix, Cassandra & Others. Finally, check that no connector is registered yet:
curl -s -H "Accept:application/json" localhost:8083/connectors/
# []
Reference: Debezium — Tutorial: Starting Kafka Connect
Look at the sample data before you change it. docker compose exec runs the MySQL client inside the mysql
container, so no client is needed on the host:
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e "SELECT * FROM customers"
id first_name last_name email
1001 Sally Thomas sally.thomas@acme.com
1002 George Bailey gbailey@foobar.com
1003 Edward Walker ed@walker.com
1004 Anne Kretchmar annek@noanswer.org
Step 2: Register the MySQL connector
A connector is a JSON document with a name and a config map. Save the following as register-mysql.json. It is
the configuration of the official tutorial, unchanged.
{
"name": "inventory-connector",
"config": {
"connector.class": "io.debezium.connector.mysql.MySqlConnector",
"tasks.max": "1",
"database.hostname": "mysql",
"database.port": "3306",
"database.user": "debezium",
"database.password": "dbz",
"database.server.id": "184054",
"topic.prefix": "dbserver1",
"database.include.list": "inventory",
"schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
"schema.history.internal.kafka.topic": "schemahistory.inventory"
}
}
The properties, and what each one means in a real migration:
| Property | Value here | Why it matters |
|---|---|---|
|
|
Selects the plugin. Each source database has its own class; see MySQL & MariaDB Connectors. |
|
|
The MySQL connector always runs a single task, because the binlog is one ordered stream. A single reader keeps the order of events. |
|
|
The address as seen from the Connect container, not from your host. A common mistake is |
|
|
A dedicated user with |
|
|
The connector joins the MySQL replication topology as a replica, so it needs a server ID that is unique among all replicas of that server. |
|
|
The logical name of the source. Every topic starts with it ( |
|
|
Only this database is captured. |
|
|
MySQL binlog events do not carry the table structure, so the connector records every DDL statement in this topic and
replays it after a restart. These properties replaced the old |
Reference: Debezium — MySQL connector properties
Register the connector with a POST to /connectors:
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" \
localhost:8083/connectors/ -d @register-mysql.json
HTTP/1.1 201 Created
Server: Jetty(12.0.34)
Location: http://localhost:8083/connectors/inventory-connector
Content-Type: application/json
{"name":"inventory-connector","config":{"connector.class":"io.debezium.connector.mysql.MySqlConnector", ... },"tasks":[],"type":"source"}
201 Created only means that Kafka Connect stored the configuration. Whether the connector actually started is a
separate question, answered by the status endpoint:
curl -s localhost:8083/connectors/inventory-connector/status | jq .
Reference: Apache Kafka 4.3 — Kafka Connect REST API
{
"name": "inventory-connector",
"connector": {
"state": "RUNNING",
"worker_id": "172.18.0.5:8083",
"version": "3.7.1.Final"
},
"tasks": [
{
"id": 0,
"state": "RUNNING",
"worker_id": "172.18.0.5:8083",
"version": "3.7.1.Final"
}
],
"type": "source"
}
Both the connector and task 0 must be RUNNING. If the task is FAILED, the status response contains a trace field
with the Java stack trace. The usual causes in this lab are a wrong host name, a wrong password, or a database that
is not ready yet. Fix the configuration with PUT /connectors/inventory-connector/config and the task restarts.
Watch the connector start
The Connect log shows the snapshot workflow that Initial Snapshots explains in detail. These are the key lines from the run, with the logger names removed:
docker compose logs connect | grep -E 'Snapshot step|Snapshot ended|Starting streaming|Connected to binlog|using binlog'
08:51:12,261 INFO MySQL||snapshot Snapshot step 1 - Preparing
08:51:12,266 INFO MySQL||snapshot Snapshot step 2 - Determining captured tables
08:51:12,353 INFO MySQL||snapshot Snapshot step 3 - Locking captured tables [inventory.addresses, inventory.customers, inventory.geom, inventory.orders, inventory.products, inventory.products_on_hand]
08:51:12,356 INFO MySQL||snapshot Flush and obtain global read lock to prevent writes to database
08:51:12,358 INFO MySQL||snapshot Snapshot step 4 - Determining snapshot offset
08:51:12,361 INFO MySQL||snapshot using binlog 'mysql-bin.000003' at position '157' and gtid ''
08:51:12,361 INFO MySQL||snapshot Snapshot step 5 - Reading structure of captured tables
08:51:12,631 INFO MySQL||snapshot Snapshot step 6 - Persisting schema history
08:51:12,663 INFO MySQL||snapshot Snapshot step 7 - Snapshotting data
08:51:12,736 INFO MySQL||snapshot Snapshot completed
08:51:12,767 INFO MySQL||streaming Starting streaming
08:51:12,837 INFO MySQL||binlog Connected to binlog at mysql:3306, starting at BinlogOffsetContext{... currentBinlogFilename='mysql-bin.000003', currentBinlogPosition=157, ...}
Read the two binlog positions together. In step 4 the connector recorded mysql-bin.000003 position 157 while it held
the read lock, then copied the rows, and finally connected to the binlog at exactly that position. Anything committed
during the copy is therefore delivered as a streaming event after the snapshot events, never lost and never mixed in.
That hand-over is what makes a snapshot plus streaming a correct baseline for a migration.
The connector creates one topic per captured table, plus the schema change topic named after the prefix and the schema history topic:
docker compose exec kafka /kafka/bin/kafka-topics.sh --bootstrap-server kafka:9092 --list
Reference: Debezium — MySQL connector: topic names
__consumer_offsets
dbserver1
dbserver1.inventory.addresses
dbserver1.inventory.customers
dbserver1.inventory.geom
dbserver1.inventory.orders
dbserver1.inventory.products
dbserver1.inventory.products_on_hand
my_connect_configs
my_connect_offsets
my_connect_statuses
schemahistory.inventory
The topic name is <topic.prefix>.<database>.<table>. The dbserver1 topic carries schema change events for
consumers that want to follow DDL, and schemahistory.inventory is internal to the connector: never consume it as
data and never delete it while the connector exists.
Step 3: Watch the customers topic
Open a second terminal and start a consumer that prints every event in dbserver1.inventory.customers from the
beginning, with its key. The Debezium Kafka image includes a watch-topic helper for this; it is a thin wrapper around
kafka-console-consumer.sh.
docker run -it --rm --name watcher --network dbz-tutorial_default \
quay.io/debezium/kafka:3.7.1.Final watch-topic -a -k dbserver1.inventory.customers
Reference: Debezium — Tutorial: Viewing a create event
-a reads from the beginning of the topic and -k prints the key, separated from the value by a tab.
dbz-tutorial_default is the network that Compose created for the project. The plain Kafka console consumer works the
same way and is what you would script:
docker compose exec kafka /kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 \
--topic dbserver1.inventory.customers --from-beginning \
--formatter-property print.key=true
Reference: Debezium — Tutorial: Viewing a create event
In Kafka 4.x the console consumer’s --property option is deprecated in favour of --formatter-property; the old
spelling still works but prints a warning.
A third option is kcat, which can print the partition offset of every message with a format string. That is useful later for checking that nothing was lost or duplicated:
docker run --rm --platform linux/amd64 --network dbz-tutorial_default edenhill/kcat:1.7.1 \
-b kafka:9092 -C -t dbserver1.inventory.customers -o beginning -e -q -f '%o|%s\n'
Reference: kcat — README
The edenhill/kcat image is published for linux/amd64 only, so on an ARM machine Docker runs it under emulation
(hence --platform). If kcat is installed on the host, use -b localhost:9092 instead; the EXTERNAL listener in
the Compose file exists for exactly this.
The snapshot events
The first four events are the snapshot of the four existing customers. Each message has a key and a value, and with
the default JSON converter each of them is a schema plus payload pair. The key of the last snapshot event:
{
"schema": {
"type": "struct",
"fields": [ { "type": "int32", "optional": false, "field": "id" } ],
"optional": false,
"name": "dbserver1.inventory.customers.Key"
},
"payload": { "id": 1004 }
}
The key is the primary key of the row. Kafka uses it to choose the partition, so every change to customer 1004 lands in the same partition, in order. Consumers that apply events to a target table rely on that ordering.
The value carries a schema that describes before, after, source, transaction, op and the timestamps, and the
payload itself. The schema is around 2.5 KB per message in this table; the payload is the part you work with. With
jq -c .payload:
{
"before": null,
"after": { "id": 1004, "first_name": "Anne", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
"source": {
"version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
"ts_ms": 1794214272000, "snapshot": "last_in_data_collection",
"db": "inventory", "sequence": null, "table": "customers",
"server_id": 0, "gtid": null, "file": "mysql-bin.000003", "pos": 157, "row": 0,
"thread": null, "query": null,
"ts_us": 1794214272000000, "ts_ns": 1794214272000000000
},
"transaction": null,
"op": "r",
"ts_ms": 1794214272715, "ts_us": 1794214272715802, "ts_ns": 1794214272715802176
}
Reference: Debezium — MySQL connector: create events
-
opisr(read): this row was copied by the snapshot, not changed by a transaction. -
beforeisnullandafterholds the whole row. -
source.snapshotmarks the position within the snapshot:first_in_data_collection,true, andlast_in_data_collectionfor the last row of this table. Streaming events have"false". -
source.fileandsource.posare the binlog position recorded in snapshot step 4; every snapshot event carries the same position.
Anatomy of a Change Event explains every field. For this lab, the
four fields that matter are op, before, after and source.
Step 4: Insert, update and delete rows
Keep the watcher running and change the data from the first terminal.
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
"INSERT INTO customers (first_name, last_name, email) VALUES ('Lena', 'Okafor', 'lena.okafor@example.com');"
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
"UPDATE customers SET first_name='Anne Marie' WHERE id=1004;"
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
"DELETE FROM addresses WHERE customer_id=1004; DELETE FROM customers WHERE id=1004;"
The addresses table has a foreign key to customers, so the address rows of customer 1004 must go first, as the
official tutorial explains. Both deletes run in one transaction here, so the addresses topic receives its delete
events from the same binlog transaction.
The create event
{
"before": null,
"after": { "id": 1005, "first_name": "Lena", "last_name": "Okafor", "email": "lena.okafor@example.com" },
"source": {
"version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
"ts_ms": 1794214340000, "snapshot": "false", "db": "inventory", "table": "customers",
"server_id": 223344, "gtid": null, "file": "mysql-bin.000003", "pos": 392, "row": 0,
"thread": 15, "query": null
},
"transaction": null,
"op": "c",
"ts_ms": 1794214340823
}
Reference: Debezium — MySQL connector: create events
op is now c, source.snapshot is "false", and the binlog position has moved on to 392. source.server_id is
the server ID of the MySQL server that wrote the change, and source.thread is the MySQL connection that ran it.
source.ts_ms (when MySQL committed the change, with second precision for MySQL) and the top-level ts_ms (when
Debezium processed it) differ by 0.8 seconds; that difference is the capture lag, and
Monitoring, Logging & Tracing shows how to measure it in
production.
The update event
{
"before": { "id": 1004, "first_name": "Anne", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
"after": { "id": 1004, "first_name": "Anne Marie", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
"source": {
"version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
"ts_ms": 1794214342000, "snapshot": "false", "db": "inventory", "table": "customers",
"server_id": 223344, "file": "mysql-bin.000003", "pos": 746, "row": 0, "thread": 16
},
"transaction": null,
"op": "u",
"ts_ms": 1794214342972
}
Reference: Debezium — MySQL connector: update events
An update carries the whole row before and after the change, because the example image runs MySQL with
binlog_row_image=FULL. A consumer can compare the two images to find out which columns changed (only first_name
here). This is information that a polling job reading the current table state never sees; see
Migration Strategies.
The delete event and the tombstone
The delete produces two messages with the same key, {"id":1004}:
{
"before": { "id": 1004, "first_name": "Anne Marie", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
"after": null,
"source": {
"version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
"ts_ms": 1794214345000, "snapshot": "false", "db": "inventory", "table": "customers",
"server_id": 223344, "file": "mysql-bin.000003", "pos": 1508, "row": 0, "thread": 17
},
"transaction": null,
"op": "d",
"ts_ms": 1794214345146
}
Reference: Debezium — MySQL connector: delete events
followed by a message whose value is null, a tombstone:
{"schema":{"type":"struct","fields":[{"type":"int32","optional":false,"field":"id"}],"optional":false,"name":"dbserver1.inventory.customers.Key"},"payload":{"id":1004}} null
Reference: Debezium — MySQL connector: tombstone events
The delete event tells consumers what was removed (the before image). The tombstone tells Kafka log compaction that
every earlier message with key 1004 may eventually be removed from a compacted topic. Two consequences for a migration
pipeline:
-
A consumer that writes to the new database must handle both: apply the
devent as a delete, and skip (or treat as a delete) a record with anullvalue. Code that calls a method on the value without a null check fails on the first tombstone. The JDBC sink handles both withdelete.enabled=true; see JDBC Sink Connector. -
tombstones.on.delete=falseon the source connector suppresses the tombstone if no consumer needs compaction. Event flattening has its own options (delete.tombstone.handling.mode); see Event Flattening.
At this point the topic holds eight messages. kcat with the %o format prints the partition offset of each, which
gives a compact summary:
0 {"op":"r","id":1001,"snapshot":"first_in_data_collection"}
1 {"op":"r","id":1002,"snapshot":"true"}
2 {"op":"r","id":1003,"snapshot":"true"}
3 {"op":"r","id":1004,"snapshot":"last_in_data_collection"}
4 {"op":"c","id":1005,"snapshot":"false"}
5 {"op":"u","id":1004,"snapshot":"false"}
6 {"op":"d","id":1004,"snapshot":"false"}
7 tombstone
Step 5: Stop Kafka Connect, change data, restart
This step shows the property that makes CDC usable for a long-running migration: the connector can be stopped for an upgrade, a crash or a redeployment, and it resumes from where it stopped.
First look at where the connector has recorded its position. Kafka Connect stores source offsets in the
my_connect_offsets topic, keyed by connector name and source partition:
docker compose exec kafka /kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 \
--topic my_connect_offsets --from-beginning --formatter-property print.key=true --timeout-ms 5000
["inventory-connector",{"server":"dbserver1"}] {"ts_sec":1794214272,"file":"mysql-bin.000003","pos":157}
Only the snapshot position (157) is stored, although three streaming events were already published. Kafka Connect does
not commit an offset for every event: it flushes offsets periodically, every offset.flush.interval.ms (60 seconds in
the Debezium image, set by its OFFSET_FLUSH_INTERVAL_MS variable), and on a clean shutdown. If the worker crashed at
this moment, it would restart from position 157 and publish the insert, update and delete again. That is the
at-least-once guarantee, and it is why every consumer that writes to the new database must be idempotent; see
Offsets, Restarts & Exactly-Once.
Now stop Kafka Connect gracefully, insert two rows while it is down, and start it again:
docker compose stop connect
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
"INSERT INTO customers (first_name, last_name, email) VALUES ('Sarah', 'Thompson', 'sarah.thompson@example.com');
INSERT INTO customers (first_name, last_name, email) VALUES ('Kenneth', 'Anderson', 'kenneth.anderson@example.com');"
docker compose start connect
While Connect is down the watcher prints nothing, because nothing is being produced. The rows are safe in the MySQL
binlog. The graceful stop committed the latest offset, which you can see by reading my_connect_offsets again:
["inventory-connector",{"server":"dbserver1"}] {"ts_sec":1794214272,"file":"mysql-bin.000003","pos":157}
["inventory-connector",{"server":"dbserver1"}] {"ts_sec":1794214345,"file":"mysql-bin.000003","pos":1352,"row":1,"server_id":223344,"event":2}
The new offset points into the delete transaction (pos 1352 is the start of that transaction, event 2 and row 1
tell the connector how many events and rows of it were already sent). Only the last offset per key counts.
When Connect is back, the connector finds this offset, skips the snapshot and continues streaming:
08:55:40,645 INFO MySQL||lifecycle Server has the binlog file 'mysql-bin.000003' required by the connector
08:55:41,232 INFO MySQL||snapshot A previous offset indicating a completed snapshot has been found.
08:55:41,233 INFO MySQL||snapshot Snapshot ended with SnapshotResult [status=SKIPPED, offset=BinlogOffsetContext{... currentBinlogFilename='mysql-bin.000003', currentBinlogPosition=1352, ...}]
08:55:41,292 INFO MySQL||streaming Starting streaming
08:55:41,378 INFO MySQL||binlog Connected to binlog at mysql:3306, starting at BinlogOffsetContext{... currentBinlogFilename='mysql-bin.000003', currentBinlogPosition=1352, ...}
The watcher then prints the two inserts that happened while Connect was down:
{"before":null,"after":{"id":1006,"first_name":"Sarah","last_name":"Thompson","email":"sarah.thompson@example.com"},
"source":{"ts_ms":1794214370000,"snapshot":"false","file":"mysql-bin.000003","pos":1857,"row":0,"thread":18},
"op":"c","ts_ms":1794214541387}
{"before":null,"after":{"id":1007,"first_name":"Kenneth","last_name":"Anderson","email":"kenneth.anderson@example.com"},
"source":{"ts_ms":1794214370000,"snapshot":"false","file":"mysql-bin.000003","pos":2208,"row":0,"thread":18},
"op":"c","ts_ms":1794214541389}
Three things to check, and the same three checks apply after every restart of a production connector:
-
Nothing was lost. Both rows written while Connect was down arrived.
-
Nothing was duplicated. The topic now has exactly ten messages (offsets 0 to 9): the eight from step 4 plus the two new inserts. The delete at offset 6 was not sent again, because the graceful stop had committed its offset.
-
The lag is visible.
source.ts_msis 08:52:50 UTC (the commit in MySQL) andts_msis 08:55:41 UTC (when the restarted connector read it): 171 seconds, the time between the commit and the moment Kafka Connect was back and streaming. A consumer of this topic was that far behind the source until the connector caught up, which took milliseconds once it was running.
There is one condition. The connector can only resume if the binlog file that holds its offset still exists. MySQL
purges old binlog files after binlog_expire_logs_seconds; if the connector is down for longer than that, it fails
on start with an error that the binlog position is no longer available, and needs a new snapshot. Size the log
retention of the legacy database for the longest outage you are willing to tolerate. See
MySQL purges binlog files used by Debezium
and Troubleshooting & Failure Recovery.
Step 6: The same lab with PostgreSQL
The PostgreSQL connector works the same way from the outside (a JSON configuration, the same envelope, the same offsets topic) but reads a different log. Instead of acting as a binlog replica, it creates a logical replication slot in the database and receives decoded WAL changes through it. Most migrations target PostgreSQL, and many legacy systems run on it, so it is worth seeing the differences once.
The postgres service is already running. Check that it is ready for logical decoding and look at the data:
docker compose exec postgres psql -U postgres -c "SHOW wal_level;"
docker compose exec postgres psql -U postgres -c "SELECT * FROM inventory.customers;"
wal_level must be logical; the example image sets it. The customers table has the same four rows as in MySQL.
Save the connector configuration as register-postgres.json:
{
"name": "inventory-pg-connector",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"tasks.max": "1",
"database.hostname": "postgres",
"database.port": "5432",
"database.user": "postgres",
"database.password": "postgres",
"database.dbname": "postgres",
"topic.prefix": "pgserver1",
"schema.include.list": "inventory",
"plugin.name": "pgoutput",
"slot.name": "debezium_tutorial",
"publication.name": "dbz_publication"
}
}
Reference: Debezium — PostgreSQL connector properties
The differences from the MySQL configuration:
-
database.dbnameis required: a PostgreSQL connector captures one database.schema.include.listthen limits it to theinventoryschema. -
topic.prefixispgserver1, notdbserver1. Both sources have aninventory.customerstable, so the same prefix would make both connectors write todbserver1.inventory.customers. Every connector in a Connect cluster needs its own prefix. -
plugin.nameispgoutput, the logical decoding plug-in built into PostgreSQL 10 and later and available on managed services. The documented default isdecoderbufs, which needs an extension installed on the server, so setpgoutputexplicitly. See plugin.name. -
slot.namenames the replication slot (defaultdebezium). One slot per connector; two connectors must never share a slot. -
publication.nameis the publication thatpgoutputreads (defaultdbz_publication). With the defaultpublication.autocreate.mode=all_tablesthe connector creates itFOR ALL TABLESand filters with the include lists itself. -
There is no
schema.history.internal.*: PostgreSQL sends the table structure with the logical decoding messages, so the PostgreSQL connector does not need a schema history topic. -
The
postgressuperuser is fine for a lab only. A production connector uses a dedicated user with theREPLICATIONattribute; see PostgreSQL Connector.
Register it the same way:
curl -s -X POST -H "Content-Type:application/json" localhost:8083/connectors/ -d @register-postgres.json | jq .name
curl -s 'localhost:8083/connectors?expand=status' \
| jq -c 'map_values([.status.connector.state, .status.tasks[0].state])'
docker compose exec postgres psql -U postgres -c \
"SELECT slot_name, plugin, slot_type, active, confirmed_flush_lsn FROM pg_replication_slots;"
Reference: Debezium — PostgreSQL connector: slot.name
"inventory-pg-connector"
{"inventory-pg-connector":["RUNNING","RUNNING"],"inventory-connector":["RUNNING","RUNNING"]}
slot_name | plugin | slot_type | active | confirmed_flush_lsn
-------------------+----------+-----------+--------+---------------------
debezium_tutorial | pgoutput | logical | t | 0/2B6BC98
The Connect log shows the connector creating the publication and the slot before it takes the snapshot:
08:58:46,353 INFO Postgres||lifecycle Connector started with no previous offset for partition 'PostgresPartition [sourcePartition={server=pgserver1}]'
08:58:46,369 INFO Postgres||postgres-connector-task Creating Publication with statement 'CREATE PUBLICATION dbz_publication FOR ALL TABLES;'
08:58:46,373 INFO Postgres||postgres-connector-task Creating replication slot with command CREATE_REPLICATION_SLOT "debezium_tutorial" LOGICAL pgoutput
08:58:46,425 INFO Postgres||snapshot Snapshot step 1 - Preparing
08:58:46,445 INFO Postgres||snapshot Read xlogStart at 'LSN{0/2B6BC98}' from transaction '795'
08:58:46,488 INFO Postgres||snapshot Snapshot step 7 - Snapshotting data
08:58:46,539 INFO Postgres||snapshot Snapshot ended with SnapshotResult [status=COMPLETED, ...]
Unlike the MySQL connector, which took a global read lock in step 3 of its snapshot, the PostgreSQL connector takes
no table locks by default (snapshot.locking.mode=none; step 3 still appears in the log but acquires nothing). It
reads the tables in a repeatable-read transaction that uses the snapshot exported when the slot was created, so the
snapshot and the slot start at the same LSN (0/2B6BC98).
Run the same changes as in MySQL. The PostgreSQL sample has no addresses table, so customer 1004 can be deleted
directly:
docker compose exec postgres psql -U postgres -c \
"INSERT INTO inventory.customers (first_name, last_name, email) VALUES ('Lena', 'Okafor', 'lena.okafor@example.com');"
docker compose exec postgres psql -U postgres -c \
"UPDATE inventory.customers SET first_name='Anne Marie' WHERE id=1004;"
docker compose exec postgres psql -U postgres -c \
"DELETE FROM inventory.customers WHERE id=1004;"
0 {"op":"r","after":{"id":1001,...},"src":{"lsn":45530264,"txId":795,"snapshot":"first"}}
1 {"op":"r","after":{"id":1002,...},"src":{"lsn":45530264,"txId":795,"snapshot":"true"}}
2 {"op":"r","after":{"id":1003,...},"src":{"lsn":45530264,"txId":795,"snapshot":"true"}}
3 {"op":"r","after":{"id":1004,...},"src":{"lsn":45530264,"txId":795,"snapshot":"last_in_data_collection"}}
4 {"op":"c","before":null,"after":{"id":1005,"first_name":"Lena",...},"src":{"lsn":45571064,"txId":796,"snapshot":"false"}}
5 {"op":"u","before":{"id":1004,"first_name":"Anne",...},"after":{"id":1004,"first_name":"Anne Marie",...},"src":{"lsn":45571680,"txId":797}}
6 {"op":"d","before":{"id":1004,"first_name":"Anne Marie",...},"after":null,"src":{"lsn":45571888,"txId":798}}
7 tombstone
The envelope is identical; only source differs. A PostgreSQL event carries the PostgreSQL position instead of a
binlog file and position:
{
"version": "3.7.1.Final", "connector": "postgresql", "name": "pgserver1",
"ts_ms": 1794214759926, "snapshot": "false", "db": "postgres",
"sequence": "[\"45571680\",\"45571680\"]",
"schema": "inventory", "table": "customers",
"txId": 797, "lsn": 45571680, "xmin": null,
"origin": null, "origin_lsn": null,
"ts_us": 1794214759926160, "ts_ns": 1794214759926160000
}
lsn is the WAL position (45571680 is 0/2B75E60 in PostgreSQL notation) and txId the transaction ID. Every
snapshot event has the same LSN and transaction, the one recorded when the slot was created, which mirrors the single
binlog position of the MySQL snapshot.
REPLICA IDENTITY decides what before contains
The update above has a full before image. That is only because the example-postgres image sets
REPLICA IDENTITY FULL on its tables. A normal PostgreSQL table uses REPLICA IDENTITY DEFAULT, which writes only the
primary key of the old row to the WAL. To see the difference, switch the table to the default and repeat an update and
a delete:
docker compose exec postgres psql -U postgres -c "ALTER TABLE inventory.customers REPLICA IDENTITY DEFAULT;"
docker compose exec postgres psql -U postgres -c "UPDATE inventory.customers SET last_name='Bailey-Ross' WHERE id=1002;"
docker compose exec postgres psql -U postgres -c "DELETE FROM inventory.customers WHERE id=1005;"
docker compose exec postgres psql -U postgres -c "ALTER TABLE inventory.customers REPLICA IDENTITY FULL;"
9 {"before":null,"after":{"id":1002,"first_name":"George","last_name":"Bailey-Ross","email":"gbailey@foobar.com"},"op":"u"}
10 {"before":{"id":1005,"first_name":"","last_name":"","email":""},"after":null,"op":"d"}
11 tombstone
The excerpt starts at offset 9; the record at offset 8 is not shown.
With DEFAULT, the update has "before": null, and the delete has a before image that contains only the real primary
key: the other columns are NOT NULL in the schema, so the connector fills them with empty strings. A consumer that
reads before.email of a delete gets "", not the deleted customer’s address. For a migration this matters in three
places:
-
an anti-corruption layer that needs the old value to translate a change (for example to find the previous status of an order) cannot get it;
-
audit or reconciliation logic that compares
beforeandaftersees nothing to compare; -
a sink that needs the old value of a non-key column to find the target row cannot find it.
Decide per table whether you need full before images, and set REPLICA IDENTITY FULL on the legacy tables that need it
(it increases WAL volume). The PostgreSQL connector can set it for you with replica.identity.autoset.values. See
PostgreSQL Connector and
Data Types & Precision for the related TOAST column behaviour.
Restart and resume with a replication slot
Repeat the restart test. Stop Connect, insert a row, look at the slot, and start Connect again:
docker compose stop connect
docker compose exec postgres psql -U postgres -c \
"INSERT INTO inventory.customers (first_name, last_name, email) VALUES ('Sarah', 'Thompson', 'sarah.thompson@example.com');"
docker compose exec postgres psql -U postgres -c \
"SELECT slot_name, active, confirmed_flush_lsn, pg_current_wal_lsn() FROM pg_replication_slots;"
docker compose start connect
slot_name | active | confirmed_flush_lsn | pg_current_wal_lsn
-------------------+--------+---------------------+--------------------
debezium_tutorial | f | 0/2B781B8 | 0/2B785D0
The slot is inactive, and its confirmed_flush_lsn stays behind the current WAL position. This is the PostgreSQL
counterpart of the binlog retention problem, and more dangerous: an inactive slot makes PostgreSQL keep every WAL
segment after confirmed_flush_lsn. A connector that stays stopped for days on a busy legacy database can fill the
disk. Monitor slot lag (pg_current_wal_lsn() minus confirmed_flush_lsn) and cap it with PostgreSQL’s
max_slot_wal_keep_size; see PostgreSQL Connector.
On start, the connector reads its offset from my_connect_offsets, checks the slot and asks PostgreSQL to continue
from there:
09:08:13,743 INFO Postgres||lifecycle Found previous partition offset PostgresPartition [sourcePartition={server=pgserver1}]: {lsn_proc=45580784, lsn_events_processed=1, messageType=DELETE, lsn_commit=45580728, lsn=45580784, txId=804, ts_usec=1794214792416671}
09:08:13,825 INFO Postgres||lifecycle Obtained valid replication slot ReplicationSlot [active=false, latestFlushedLsn=LSN{0/2B781B8}, catalogXmin=804]
09:08:13,975 INFO Postgres||snapshot A previous offset indicating a completed snapshot has been found.
09:08:14,452 INFO Postgres||streaming Starting streaming
09:08:14,452 INFO Postgres||streaming Retrieved latest position from stored offset 'LSN{0/2B781F0}'
09:08:14,756 INFO Postgres||streaming WAL resume position 'LSN{0/2B78260}' discovered
09:08:15,030 INFO Postgres||streaming Processing messages
09:08:15,479 INFO Postgres||lifecycle 1 records sent during previous 00:00:22.08, last recorded offset of {server=pgserver1} partition is {lsn_proc=45581472, ..., messageType=INSERT, txId=806, ...}
{"after":{"id":1006,"first_name":"Sarah","last_name":"Thompson","email":"sarah.thompson@example.com"},
"op":"c","lsn":45581472,"src_ts":1794214812964,"ts_ms":1794215295088}
The insert committed at 09:00:12 UTC was delivered at 09:08:15 UTC when the connector came back, at topic offset 12,
after the tombstone at offset 11. The log reports exactly one record sent after the restart, and that record is the
insert made while Connect was stopped: nothing lost, nothing repeated. The slot is active again and its
confirmed_flush_lsn advances as the connector commits offsets.
Step 7: Clean up
Deleting a connector removes its configuration from Kafka Connect, but not what it created in the source database. For PostgreSQL that means the replication slot and the publication. A forgotten slot keeps WAL forever, so drop both:
curl -s -o /dev/null -w '%{http_code}\n' -X DELETE localhost:8083/connectors/inventory-pg-connector
# 204
docker compose exec postgres psql -U postgres -c "SELECT slot_name, active FROM pg_replication_slots;"
# slot_name | active
# -------------------+--------
# debezium_tutorial | f
docker compose exec postgres psql -U postgres -c "SELECT pg_drop_replication_slot('debezium_tutorial');"
docker compose exec postgres psql -U postgres -c "DROP PUBLICATION dbz_publication;"
slot.drop.on.stop=true makes the connector drop its slot on every graceful stop. That is convenient in tests but
wrong for a migration pipeline: after a restart the connector would have to take a new snapshot, because the changes
between the stop and the start are gone with the slot.
The MySQL connector leaves nothing in the database, so deleting it is enough. Then stop and remove the whole stack, including its volumes:
curl -s -X DELETE localhost:8083/connectors/inventory-connector
docker compose down -v
docker ps -a --filter name=dbz-tutorial
Reference: Debezium — Tutorial: Cleaning up
The last command must print only the header line. Because Kafka keeps its data inside the container and the
Compose file defines no named volumes, down -v removes all topics, offsets and connector configurations; the next
docker compose up -d starts from nothing and every connector takes a new snapshot.
What can go wrong
| Symptom | Likely cause | Fix |
|---|---|---|
|
Kafka Connect is still scanning plugins, or the container was killed. |
Wait and retry. Check |
Task state |
|
Use the Compose service name and the container port ( |
Registration returns |
A connector with that name already exists. |
Update it with |
Two connectors write to the same topics |
Same |
Give each connector its own prefix. |
A host client hangs or fails on |
The client got the internal advertised listener. |
Connect from the host with |
PostgreSQL connector fails with a |
|
Set |
PostgreSQL disk grows while Connect is down |
The inactive replication slot retains WAL. |
Restart the connector, or drop the slot if the connector is gone for good. |
After a restart, events already seen arrive again |
The worker stopped without committing its last offset (crash or kill). |
Expected under at-least-once delivery. Make consumers idempotent. |
From the tutorial to the Bookshop migration
Everything in this lab carries over to the legacy Bookshop pipeline; only the scale and the source change:
| Tutorial | Bookshop migration | Covered in |
|---|---|---|
|
|
|
|
|
|
watch-topic and kcat |
The JDBC sink |
|
Four-row snapshot |
A multi-gigabyte snapshot of |
|
One Connect container, one Kafka node |
A replicated Kafka cluster and a Connect cluster, often on Kubernetes |
|
Restart test by hand |
Automated restart and failure tests |
The Debezium debezium-examples tutorial directory has Compose files for the same tutorial with MongoDB, SQL Server, Oracle and other databases. For Kafka Connect itself (workers, converters, the REST API), see Kafka Connect.
References
The Compose stack, both connector configurations and every command on this page were run with Docker on 2026-11-09 against the 3.7.1.Final images; the event and log output is real, trimmed for width, with timestamps shortened.