---
title: "CDC Sink for PostgreSQL: Overview"
description: "CDC Sink support for PostgreSQL - using logical replication to stream changes into RavenDB in real time."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/overview"
version: "7.2"
language: "csharp"
---

# CDC Sink for PostgreSQL: Overview

> Client language: C#.
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - CDC Sink supports PostgreSQL as a source database by using [logical replication](https://www.postgresql.org/docs/current/logical-replication.html).
>
> - PostgreSQL streams row-level changes continuously through a logical replication slot.  
>   The CDC Sink task consumes this stream and applies INSERTs, UPDATEs, and DELETEs to RavenDB documents as they are received.
>
> - In this article:
>   - [Connection string](#connection-string)
>   - [How it works](#how-it-works)
>   - [Prerequisites](#prerequisites)
>   - [PostgreSQL-specific settings](#postgresql-specific-settings)
>   - [Task configuration](#task-configuration)

## Connection string {#connection-string}

Create a [SqlConnectionString](https://docs.ravendb.net/7.2/server/ongoing-tasks/etl/sql.md#add-an-sql-connection-string) with `FactoryName` set to `"Npgsql"`.

### Sync

```csharp
store.Maintenance.Send(new PutConnectionStringOperation<SqlConnectionString>(
    new SqlConnectionString
    {
        Name = "MyPostgresConnection",
        FactoryName = "Npgsql",
        ConnectionString = "Host=myserver;Port=5432;Database=mydb;Username=cdc_user;Password=..."
    }));
```

### Async

```csharp
await store.Maintenance.SendAsync(new PutConnectionStringOperation<SqlConnectionString>(
    new SqlConnectionString
    {
        Name = "MyPostgresConnection",
        FactoryName = "Npgsql",
        ConnectionString = "Host=myserver;Port=5432;Database=mydb;Username=cdc_user;Password=..."
    }));
```

## How it works {#how-it-works}

CDC Sink uses PostgreSQL logical replication to receive a continuous stream of row-level changes without polling.

Key PostgreSQL concepts:

- **Replication slot**  
  A server-side object that tracks how far CDC Sink has read in the logical replication stream.  
  It also causes PostgreSQL to retain the required WAL segments until CDC Sink confirms receipt.
- **Publication**  
  Defines which tables are included in the replication stream.
  CDC Sink creates or reuses a publication for the configured tables when the PostgreSQL user in the connection string has sufficient permissions.
- **WAL (Write-Ahead Log)**  
  The durable log PostgreSQL uses as the source for logical replication.  
  If a CDC Sink task is inactive or paused while its replication slot exists, WAL segments can accumulate.

## Prerequisites {#prerequisites}

Before creating a CDC Sink task for PostgreSQL, verify the source database settings, permissions, and table requirements.
See [Prerequisites Checklist](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/prerequisites-checklist.md)
for the full list, including:

- PostgreSQL version 10 or later
- WAL level set to `logical`
- Sufficient `max_replication_slots` and `max_wal_senders`
- A PostgreSQL user with `REPLICATION` privilege and `SELECT` on each table CDC Sink will read
- `REPLICA IDENTITY` configuration for embedded tables whose join columns are not part of the primary key

## PostgreSQL-specific settings {#postgresql-specific-settings}

Use `CdcSinkConfiguration.Postgres` when you want to specify the PostgreSQL replication slot and publication names explicitly:

```csharp
Postgres = new CdcSinkPostgresSettings
{
    SlotName = "my_slot",
    PublicationName = "my_publication"
}
```

If either name is omitted, the CDC Sink task generates it when the task is created:
`rvn_cdc_s_{taskId}` for the slot and `rvn_cdc_p_{taskId}` for the publication.
The names are stored with the task and do not change on later updates.

To let the CDC Sink task create the PostgreSQL slot and publication itself,
the PostgreSQL user configured in the CDC Sink connection string must have sufficient permissions.

See [Initial Setup](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/initial-setup.md) for details.

## Task configuration {#task-configuration}

Most CDC Sink task configuration is shared across supported source database engines.  
See [Configuration Reference](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/configuration-reference.md) for the full API,
including table mappings, delete behavior, patches, and PostgreSQL-specific settings.

For PostgreSQL, `SourceTableSchema` defaults to `"public"` when omitted.
