Skip to content

Repository files navigation

Postgres Stream

Postgres Stream

Reliably stream Postgres table changes to external systems with automatic failover and zero event loss.

What is Postgres Stream?

Postgres Stream captures changes from your Postgres tables and delivers them to external systems like Kafka, RabbitMQ, Redis, Webhooks, and cloud services. It uses Postgres native logical replication and stores events durably in the database itself.

Note

Postgres Stream is production ready and used in production for months already, processing millions of events per day.

Key Features

  • Single binary - No complex infrastructure or high-availability destinations required
  • Postgres-native durability - Events are stored in the database, WAL can be released immediately
  • Zero data loss - As long as downtime is less than partition retention (7 days by default)
  • Automatic recovery - Handles both sink failures and slot invalidation without operator intervention

How It Works

Events are inserted into the pgstream.events table and streamed via logical replication to your sink.

Two ways to create events:

  1. Subscriptions (optional) - Managed triggers
  2. Manual inserts - Insert directly into pgstream.events from your application or database functions

Trade-offs

While Postgres Stream provides strong durability guarantees, there are some considerations:

  • Small overhead - Additional INSERT into events table on every subscribed operation
  • Partition management - Monitor partition growth if event volume is very high
  • Not for dynamic subscriptions - Each subscription change recreates database triggers

Supported Sinks

SinkUse Case
KafkaHigh-throughput event streaming
NATSLightweight pub/sub messaging
RabbitMQEnterprise message broker
Redis StringsKey-value caching
Redis StreamsAppend-only event log
WebhookHTTP POST delivery
AWS SQSManaged queue service
AWS SNSManaged pub/sub service
AWS KinesisReal-time data streaming
GCP Pub/SubGoogle Cloud messaging
ElasticsearchSearch indexing
MeilisearchSearch indexing

Quick Start

# config.yamlstream:
id: 1pg_connection:
host: localhostport: 5432name: mydbusername: postgrespassword: postgrestls:
enabled: falsebatch:
max_size: 1000max_fill_secs: 5sink:
type: kafkabrokers: localhost:9092topic: events
# Run with Docker
docker run -v $(pwd)/config.yaml:/config.yaml \
ghcr.io/psteinroe/postgres-stream:kafka-latest

License

MIT

About

Reliable event streaming from Postgres

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages