Skip to content

pg_topics

PostgreSQL tables as JSON topics with a Kafka-protocol listener

pg_topics · PostgreSQL tables as JSON topics with a Kafka-protocol listener

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102467pg_topicspg_topics0.1.0FEATPostgreSQLRust

PostgreSQL · 17

Relationships
Requiresplpgsql

Usage

Sources:

pg_topics 0.1.0 exposes PostgreSQL tables as JSON event topics through SQL functions and a Kafka-protocol listener. The reviewed Supatype distribution documents PostgreSQL 17. It requires shared preloading, server-side TLS configuration and an externally enforced failover-fencing policy. It is not a complete Kafka implementation.

Enable a Database

Install matching PostgreSQL 17 libraries, append pg_topics to shared_preload_libraries, and configure pg_topics.databases, TLS certificate/key and pg_topics.advertised_host. Set pg_topics.failover_is_fenced only after ensuring an old primary cannot continue serving after promotion. Restart PostgreSQL, then create the nonrelocatable extension as a superuser in each allowed database; its schema is topic.

CREATE EXTENSION pg_topics;
SELECT topic.create_topic('public.orders_q', band_count => 4);
SELECT topic.publish('public.orders_q', '{"order_id":1}', key => 'customer-42');
SELECT * FROM topic.fetch('public.orders_q', band => 0, from_offset => 0, max_rows => 500);

Publishing through SQL participates in the caller’s transaction. A band corresponds to a Kafka partition. Kafka clients use the full schema.table_q name, SASL_SSL, PLAIN authentication, and a PostgreSQL role/password. Grant topic access deliberately; Kafka does not introduce a separate authorization database.

Capacity and Delivery

The source registers five background workers per configured database: stamper, replicated stamper, partition, sync and listener. Reserve max_worker_processes accordingly. Each authenticated Kafka connection also holds a PostgreSQL connection, so size max_connections and pg_topics.max_clients together. An optional sync worker maintains a current-state table; ordinary SQL can read topic history.

Review topic durability and replication settings before changing acknowledgement behavior. A lost response may require a retry; idempotent and non-idempotent producers have different duplicate handling. PostgreSQL backup/recovery and the external fencing guarantee are part of the message-delivery design.

Compatibility Limits

Values must parse as JSON; keys are UTF-8 text of at most 40 characters, and table names must end in _q. Kafka transactions are unsupported. Use the upstream compatibility table when choosing client/admin APIs. Bound SQL fetch sizes, retention, connection counts and the number of databases; throughput examples from the project are measurements, not sizing guarantees.

Table reader