---
title: "pgstream — PostgreSQL CDC with DDL Tracking | Xata"
description: "Open source change data capture for PostgreSQL. Replicates data and schema changes to Postgres, Elasticsearch, Kafka, and more. Built-in anonymization for safe dev environments."
source: "https://xata.io/open-source/pgstream"
---

Postgres replication
with DDL and transforms
=======================

Open source CDC tool that replicates PostgreSQL data and schema changes to any target. Built-in anonymization for safe dev and staging environments.

[View on GitHub](https://github.com/xataio/pgstream)[Read the docs](/docs/overview)

## CDC that actually handles schema changes

Traditional CDC tools break when you ALTER a table. pgstream tracks DDL changes natively and replicates them alongside your data.

### DDL change tracking

Unlike traditional CDC tools, pgstream captures and replicates schema changes alongside data changes. No manual intervention when tables evolve.

### Multi-target streaming

Stream changes to PostgreSQL, Elasticsearch, OpenSearch, Kafka, or webhooks. Schema-based partitioning for Kafka, custom targets via the Go library.

### Built-in anonymization

Transform column values during replication using greenmask, neosync, or go-masker integrations. Anonymize PII on the fly as data flows from production to dev.

### Snapshots

Initial and on-demand PostgreSQL snapshots for bulk data loads. Useful when continuous replication is overkill or you need to bootstrap a new target.

### Modular & embeddable

Use as a standalone CLI tool or embed as a Go library in your own applications. Only requires PostgreSQL as a dependency — no ZooKeeper, no Kafka required.

### Stateless schema replication

Since v1.0, pgstream uses a custom event trigger for DDL capture. No intermediate schema state table — all DDL statements are replicated, not just a curated subset.

Targets

## Stream to where your data needs to go

Out-of-the-box support for the most common targets, with a Go library for building custom ones.

#### PostgreSQL

Postgres-to-Postgres replication with DDL tracking. Keep staging in sync with production.

#### Elasticsearch / OpenSearch

Stream changes to search indexes. Schema changes are automatically reflected.

#### Kafka

Schema-based partitioning for event streaming. Integrate with your existing data pipeline.

#### Webhooks

Send change events to any HTTP endpoint. Build custom integrations without writing a connector.

Anonymization

## Safe replication with built-in transforms

Configure column-level transformations to anonymize sensitive data during replication. Production data flows to dev and staging with PII automatically masked — no separate pipeline needed.

| Source column      | Transformer         | Target output      |
| ------------------ | ------------------- | ------------------ |
| alice@company.com | greenmask/email     | u7k2m@example.com |
| +1-555-0123        | neosync/phone       | +1-555-9847        |
| alice_smith        | go-masker/username  | user_x8k2p         |
| 34                 | greenmask/noise_int | 37                 |

Quickstart

## Start streaming in four steps

Available as a Go binary or Docker image. Single dependency: a PostgreSQL source database.

Point pgstream at your source Postgres and choose a target: another Postgres instance, Elasticsearch, Kafka, or webhooks.

Configure column-level anonymization rules. Mask emails, hash phone numbers, randomize ages — all while maintaining referential integrity.

pgstream begins replicating data and schema changes in real time. DDL changes flow downstream automatically.

## Built for production

1,000+ GitHub stars

Apache 2.0 license

Go binary + library

Postgres-only dependency

## Branch your database in seconds

[Get started](https://console.xata.io/signup)[Get in Touch](https://cal.com/team/xata/xata-sales)
