Lag increasing for Slot created by debezium kafka connect
09:48 16 Apr 2025

I'm using confluent kafka for streaming of data and using postgres plugin for source and jdbc for sink connectors

While creating a connector with the following configuration:

{"name": "counterops_name",   
"config": {
    "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
    "database.hostname": "**.**.***.***",
    "database.port": 5432,
    "database.user": "***",
    "database.password": "****",
    "database.dbname": "***",
    "database.server.name": "**.**.***.***",
    "table.include.list": "schema.table",
    "snapshot.mode": "initial",
    "time.precision.mode": "connect",
    "database.history.kafka.bootstrap.servers": "broker1:9091,broker2:9091,broker3:9091,broker4:9091,broker5:9091",
    "database.history.kafka.topic": "schema-changes.schema",
    "topic.prefix": "prefix",
    "plugin.name": "pgoutput",
    "slot.name": "slot_name",
    "key.converter": "io.confluent.connect.avro.AvroConverter",
    "key.converter.schema.registry.url": "https://broker3:8081,https://broker4:8081,https://broker5:8081",
    "key.converter.enhanced.avro.schema.support": true,
    "value.converter": "io.confluent.connect.avro.AvroConverter",
    "value.converter.schemas.enable": true,
    "value.converter.schema.registry.url": "https://broker3:8081,https://broker4:8081,https://broker5:8081",
    "transforms": "unwrap,removeFields",
    "transforms.unwrap.type": "io.debezium.transforms.ExtractNewRecordState",
    "transforms.removeFields.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
    "transforms.removeFields.blacklist": "before,source",
    "include.schema.changes": true,
    "publication.name": "dbz_schema_table",
    "publication.autocreate.mode": "filtered",
    "tasks.max": "5",
    "topic.creation.default.replication.factor": 5,
    "topic.creation.default.partitions": 5,
    "poll.interval.ms": "1000",
    "offset.flush.interval.ms": "5000"
}}

The problem is when the replication slot is becoming inactive after some days and the data stops flowing while the connector being in running state.

On further observation it is observed that the replication is going from reserved to extended

the following query is giving replicationSlotLag and confirmedLag which is greated than my wal_size

SELECT slot_name,
 pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) as replicationSlotLag,
 pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)) as confirmedLag,
 active
FROM pg_replication_slots;

Why are replicationSlotLag and confirmedLag increasing even though the kafka connector is in running state and how to solve this issue of replicationSlotLag and confirmedLag increasing?

sql postgresql jdbc apache-kafka-connect wal