Skip to content

pg_kafka_events

Publishes PostgreSQL logical-decoding change events to Apache Kafka through a background worker.

pg_kafka_events · Publishes PostgreSQL logical-decoding change events to Apache Kafka through a background worker.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100341pg_kafka_eventspg_kafka_events1.0ETLApache-2.0C

Usage

Sources:

pg_kafka_events is a preloaded background worker that forks pg_recvlogical, reads newline-delimited logical-decoding output, and publishes each change through librdkafka. The default decoder is decoding_json; one configured database is streamed to one Kafka topic.

Server Configuration

shared_preload_libraries = 'pg_kafka_events'
wal_level = logical
max_replication_slots = 4
max_wal_senders = 4
kafka.database_name = 'appdb'
kafka.topic = 'row_changes'
kafka.bootstrap_servers = 'kafka1:9092'

Install librdkafka, the chosen logical-decoding plugin, and the configured pg_recvlogical binary before restarting PostgreSQL. After restart, register the extension as a superuser:

CREATE EXTENSION pg_kafka_events;

The install SQL is empty; preloading starts the worker, while CREATE EXTENSION only records version 1.0 in that database.

Caveats

  • The worker always uses the replication slot name kafka_events. A stopped or failing consumer can retain WAL indefinitely; monitor slot lag and define an operator recovery procedure.
  • This 2017 implementation does not provide transactional grouping, acknowledgements exposed to PostgreSQL, retries coordinated with the replication position, or an exactly-once guarantee. Validate duplicates and loss behavior under Kafka and process failures.
  • Decoder lines are accumulated in a fixed 64 KiB static buffer without a length guard. Large row-change messages can overrun it; do not deploy the reviewed code without remediation.
  • Published payloads are also emitted as PostgreSQL notices, potentially copying row data into server logs. The only upstream tag is 0.1 even though control and catalog use 1.0.

Table reader