---
title: "CDC Sink for PostgreSQL: Permissions and Roles"
description: "PostgreSQL permissions required by the CDC Sink user, including minimum privileges, automatic setup permissions, and dedicated user creation examples."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/permissions-and-roles"
version: "7.2"
---

# CDC Sink for PostgreSQL: Permissions and Roles

> 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**
>
> - This page documents the PostgreSQL permissions required by the role configured in the CDC Sink connection string, and how to grant them.
>
> - In this article:
>   - [Minimum permissions](#minimum-permissions)
>   - [Permissions for automatic setup](#permissions-for-automatic-setup)
>   - [Creating a dedicated CDC user](#creating-a-dedicated-cdc-user)
>   - [Check permissions with Verify tables](#check-permissions-with-verify-tables)

## Minimum permissions {#minimum-permissions}

The **CDC Sink user** is the PostgreSQL role in the connection string that the CDC Sink task uses to connect to the source database.
Throughout this page, `cdc_user` is used as the example username for this role.

At a minimum, the CDC Sink user needs:

- **`REPLICATION`** role attribute - allows the user to use logical replication and create a logical replication slot.
- **`SELECT`** on each table mapped by the CDC Sink task - required for the initial load phase.

Example:

```sql
-- Grant replication privilege
ALTER USER cdc_user REPLICATION;

-- Grant SELECT on each table
GRANT SELECT ON TABLE orders TO cdc_user;
GRANT SELECT ON TABLE order_lines TO cdc_user;
GRANT SELECT ON TABLE customers TO cdc_user;
```

With only these permissions, CDC Sink can create the replication slot,
but a database administrator must create or update the publication before the task starts
unless the user also has the publication permissions described below.

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

## Permissions for automatic setup {#permissions-for-automatic-setup}

To let CDC Sink create the replication slot and create or update the publication automatically,  
the PostgreSQL user needs the minimum permissions above plus publication-management permissions.

**Create replication slots:**

The `REPLICATION` role attribute listed under [Minimum permissions](#minimum-permissions) is enough for CDC Sink to create the logical replication slot:

```sql
ALTER USER cdc_user REPLICATION;
```

**Create and update publications:**

Creating a publication requires `CREATE` on the database and ownership of the tables included in it.  
Adding tables to an existing publication requires ownership of the publication and the tables being added  
(`SUPERUSER` satisfies these requirements):

```sql
GRANT CREATE ON DATABASE mydb TO cdc_user;

-- The user must also own the tables added to the publication.
-- To add tables to an existing publication, the user must also own the publication.
-- Otherwise, a database administrator must create/update the publication manually.
```

> **Warning**
>
> Granting `SUPERUSER` gives the user unrestricted access to the database server.
> For production environments, prefer granting only the specific privileges required, or have a database administrator manage the publication manually.

> **Note**
>
> For added security in production, consider having your database administrator create or update the publication manually,
> rather than granting CDC Sink ownership of application tables.  
> The CDC Sink user still needs `REPLICATION` and `SELECT` on the relevant tables.
> See [Initial Setup](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/initial-setup.md).

## Creating a dedicated CDC user {#creating-a-dedicated-cdc-user}

It is recommended to use a dedicated PostgreSQL user for CDC Sink rather than an application or admin user.

Example setup:

```sql
-- Create the user with replication privilege
CREATE USER cdc_user WITH PASSWORD 'secure_password' REPLICATION;

-- Grant SELECT on every table mapped by the CDC Sink task
GRANT SELECT ON TABLE orders TO cdc_user;
GRANT SELECT ON TABLE order_lines TO cdc_user;

-- If CDC Sink should create the publication automatically:
GRANT CREATE ON DATABASE mydb TO cdc_user;

-- The user must also own every table added to the publication.
-- To add tables to an existing publication, the user must also own the publication.
-- Otherwise, a database administrator must create/update the publication manually.
ALTER TABLE orders OWNER TO cdc_user;
ALTER TABLE order_lines OWNER TO cdc_user;
```

> **Warning**
>
> Transferring table ownership with `ALTER TABLE ... OWNER TO` can affect the owning application,
> including who can alter or drop the table and who controls table-level privileges.
> For production environments, prefer having a database administrator create or update the publication manually unless table ownership transfer is acceptable.

## Check permissions with Verify tables {#check-permissions-with-verify-tables}

[**Verify tables**](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/create-task.md#verify-tables) in Studio, or the [dry-run REST endpoint](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/create-task.md#verify-the-configuration), connects as the CDC Sink user and runs the task's setup steps once,
so it reports missing permissions before you save the task.

Verification can fail with the following permission errors:

- *"Insufficient permissions to create replication slot '\<name>'..."*:  
  The CDC Sink user does not have the `REPLICATION` role attribute.

- *"Insufficient permissions to create publication '\<name>'..."*:  
  The publication does not exist, and the CDC Sink user cannot create it.  
  Grant `CREATE` on the database and ownership of the published tables,  
  or have a database administrator create the publication.

- A PostgreSQL *permission denied* error for a table:  
  The CDC Sink user does not have `SELECT` on a configured table.

When the publication and the slot already exist, verification does not create them,  
so it does not check the permissions needed to create them.

Verification also reports warnings about publication coverage and `REPLICA IDENTITY FULL`,  
which point to permissions the task needs when it starts,
see [Table verification fails or returns warnings](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/troubleshooting.md#table-verification-fails-or-returns-warnings).

## See also

- [Prerequisites Checklist](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/prerequisites-checklist.md)
- [Initial Setup](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/initial-setup.md)
- [Cleanup and Maintenance](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/cleanup-and-maintenance.md)
