Hasty Briefsbeta

Show HN: PgHook – Docker image that streams PostgreSQL row changes to webhooks

9 days ago
  • #Webhook
  • #Replication
  • #PostgreSQL
  • PgHook streams PostgreSQL change events via logical replication (PgOutput2Json) to a webhook.
  • Distributed as a small 23.17 MB container image (AOT-compiled .NET 9, Alpine).
  • Enable logical replication by setting `wal_level = logical` in `postgresql.conf` and restart PostgreSQL.
  • Create a publication for tables to watch: `CREATE PUBLICATION mypub FOR TABLE table1, table2;`.
  • Run PgHook with required environment variables: `PGH_POSTGRES_CONN`, `PGH_PUBLICATION_NAMES`, `PGH_WEBHOOK_URL`.
  • Optional: Use a permanent replication slot with `PGH_USE_PERMANENT_SLOT=true` and `PGH_REPLICATION_SLOT=myslot`.
  • Each change is a compact JSON object, delivered in batches (configurable via `PGH_BATCH_SIZE`).
  • Webhook requests can be signed with `PGH_WEBHOOK_SECRET` for authenticity and freshness verification.
  • Configuration is via environment variables, including timeouts, keep-alive, and connection pooling.
  • Non-success responses are retried three times (2s, 4s, 8s delays) before replication restarts after 10s.
  • Example Docker Compose setup includes PostgreSQL, PgHook, and a test API for demonstration.