---
title: "CDC Sink: Create Task"
description: "How to create a CDC Sink task using the RavenDB Client API (AddCdcSinkOperation) and through the Management Studio."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/create-task"
version: "7.2"
language: "csharp"
---

# CDC Sink: Create Task

> 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**
>
> - A CDC Sink task consumes Change Data Capture streams from a relational source database  
>   (PostgreSQL, SQL Server, or MySQL/MariaDB) and applies inserts, updates, and deletes to documents in RavenDB.
>
> - This article shows how to **create** a CDC Sink task using the Client API, Studio, or REST API.
>
> - In this article:
>   - [Create a CDC Sink task via Client API](#create-a-cdc-sink-task-via-client-api)
>   - [Create a CDC Sink task via Studio](#create-a-cdc-sink-task-via-studio)
>     - [Create task](#create-task)
>     - [Configure basic settings](#configure-basic-settings)
>     - [Schema explorer](#schema-explorer)
>     - [Configured tables](#configured-tables)
>     - [Add missing root tables](#add-missing-root-tables)
>     - [Configure linked tables](#configure-linked-tables)
>     - [Configure embedded tables](#configure-embedded-tables)
>     - [Test mapping](#test-mapping)
>     - [Advanced settings](#advanced-settings)
>     - [Verify tables](#verify-tables)
>     - [Save the task configuration](#save-the-task-configuration)
>     - [The created task](#the-created-task)
>   - [Create a CDC Sink task via REST API](#create-a-cdc-sink-task-via-rest-api)

## Create a CDC Sink task via Client API {#create-a-cdc-sink-task-via-client-api}

Use `AddCdcSinkOperation` to create a new CDC Sink task from a `CdcSinkConfiguration`.

The configuration references a registered SQL connection string by name.
CDC Sink uses the same `SqlConnectionString` type as [SQL ETL](https://docs.ravendb.net/7.2/server/ongoing-tasks/etl/sql.md);
the connection string's `FactoryName` determines the source engine.

Optionally set `SkipInitialLoad = true` only when the target RavenDB database already contains the initial data and the task should start from new CDC changes.

See [Configuration Reference](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/configuration-reference.md)
for the full list of configuration classes and properties.

### Sync

```csharp
var config = new CdcSinkConfiguration
{  
    // Unique name for the CDC Sink task
    Name = "OrdersSync",   

    // Name of an existing SqlConnectionString, 
    // its FactoryName selects the source database engine
    ConnectionStringName = "MyPostgresConnection",
    
    // Optional: set to true only if RavenDB already contains the initial data.
    // SkipInitialLoad = true,
    
    Tables = new List<CdcSinkTableConfig>
    {
        new CdcSinkTableConfig
        {
            // Map the source table to the Orders collection in RavenDB    
            CollectionName = "Orders", 
            SourceTableName = "orders",   

            // Primary key columns are used to generate document IDs
            // and must be included in Columns    
            PrimaryKeyColumns = new List<string> { "id" },
    
            // Map source columns to RavenDB document properties.
            Columns =
            [
                new CdcColumnMapping() { Column = "id",            Name = "Id" },
                new CdcColumnMapping() { Column = "customer_name", Name = "CustomerName" },
                new CdcColumnMapping() { Column = "total",         Name = "Total" },
            ]
        }
    }
};

// Execute the operation by passing it to Maintenance.Send    
var result = store.Maintenance.Send(new AddCdcSinkOperation(config));

long taskId = result.TaskId;
```

### Async

```csharp
var config = new CdcSinkConfiguration
{  
    // Unique name for the CDC Sink task
    Name = "OrdersSync",   

    // Name of an existing SqlConnectionString, 
    // its FactoryName selects the source database engine
    ConnectionStringName = "MyPostgresConnection",
    
    // Optional: set to true only if RavenDB already contains the initial data.
    // SkipInitialLoad = true,
    
    Tables = new List<CdcSinkTableConfig>
    {
        new CdcSinkTableConfig
        {
            // Map the source table to the Orders collection in RavenDB    
            CollectionName = "Orders", 
            SourceTableName = "orders",   

            // Primary key columns are used to generate document IDs 
            // and must be included in Columns    
            PrimaryKeyColumns = new List<string> { "id" },
    
            // Map source columns to RavenDB document properties.
            Columns =
            [
                new CdcColumnMapping() { Column = "id",            Name = "Id" },
                new CdcColumnMapping() { Column = "customer_name", Name = "CustomerName" },
                new CdcColumnMapping() { Column = "total",         Name = "Total" },
            ]
        }
    }
};

// Execute the operation by passing it to Maintenance.SendAsync    
var result = await store.Maintenance.SendAsync(new AddCdcSinkOperation(config));

long taskId = result.TaskId;
```

`AddCdcSinkOperationResult`:

| Property | Type | Description |
| - | - | - |
| `TaskId` | `long` | Assigned task ID |
| `RaftCommandIndex` | `long` | Raft index of the command |

## Create a CDC Sink task via Studio {#create-a-cdc-sink-task-via-studio}

### Create task

![Add a database task](https://docs.ravendb.net/assets/images/create-task-1-7211d29b629064a4731f10bf76c60126.png)

1. Navigate to **Databases** → your database → **Tasks** → **Ongoing Tasks**.
2. Click **Add a Database Task**

---

![Select CDC Sink](https://docs.ravendb.net/assets/images/create-task-2-d8c303716f625c564a04bb29314e9b9d.png)

1. The **Add a database task** view opens.
2. Filter by the **Sink** category to show only source-to-RavenDB sink tasks.
3. Select the **CDC Sink** task type.

---

### Configure basic settings

![Basic task settings](https://docs.ravendb.net/assets/images/create-task-3-b96feb35dcfba98bf7033278c21789d5.png)

1. **Configure basic settings**  
   In this section you specify the task name, select a connection string, and configure task options.
2. **Task Name**  
   Enter a unique name for the CDC Sink task.
3. **Task State**  
   Set the initial state, **Enabled** or **Disabled**.
4. **Connection String**  
   Select an existing SQL connection string to the source database.
5. Alternatively, click **Create a new SQL connection string** to define a new one.
6. For PostgreSQL connections, you can optionally set a custom **Publication Name** and **Slot Name**.  
   Leave these fields empty to let the server auto-generate both values.
7. **Set Responsible Node**  
   Optionally pin the task to a specific node in the database group.
8. **Skip initial load**  
   Enable only if RavenDB already contains the initial data and the task should start from new CDC changes.
9. **Raw config**  
   Toggle to view or paste the task's JSON configuration directly.  
   Useful for copying a configuration between environments.

---

### Schema explorer

![Discovered tables](https://docs.ravendb.net/assets/images/create-task-4-c0013ab7decd3ad72d1b2651e0e757fc.png)

1. **Schema Explorer**  
   In this section you can discover existing tables from the configured connection.
2. **Discover tables**  
   Click to query the source database for tables.
3. **Available tables**  
   Discovered tables appear here showing each table's name, primary keys, column count, and any warnings.

![Select source tables](https://docs.ravendb.net/assets/images/create-task-5-fc4190ed8f6604f44e2843529ecee4ca.png)

1. **Select tables**  
   Check the box next to each source table you want to sink into RavenDB as documents.
2. **Configure selected tables**  
   Click *Configure selected tables* to add the selected tables to the configuration panel below,  
   where you map their columns to RavenDB collections and document properties.

---

### Configured tables

![Root table mapping](https://docs.ravendb.net/assets/images/create-task-6-18cef9c6bdb44a30f79451e540ead428.png)

1. **Configured Tables** - In this section, configure how source tables are mapped to target RavenDB collections.
2. **Tables** - the list of configured tables. Select a table to edit its mapping.
   - A table can be a **root** table (mapped directly to its own collection),  
     or a table nested under a root table - either **linked** or **embedded** (see the sections below).
   - In this example, `orders` is a root table with `customers` nested under it as a linked table (marked with 🔗);
     `customers` also appears on its own as a separate root table.
3. **Source schema** - the schema the source table belongs to (e.g. `public`).
4. **Source table** - the name of the source table.
5. **Target collection** - the RavenDB collection that documents are written to.
6. **Primary key columns** - Columns that uniquely identify each source row.  
   Their values are used to derive the RavenDB document ID.  
   Click **Add primary key column** to add more.
7. **Source column** - the column name in the source table. Click **Add field mapping** to add more.
8. **Target property** - the RavenDB document field where the source column value will be stored.
9. **Type** - select how the source column value is stored in the document:
   - `Default` - stored as a regular property
   - `JSON` - parsed as JSON before storing
   - `Attachment` - stored as a RavenDB attachment
10. **Advanced settings** - expand to configure patch scripts and delete handling.
11. **Verify tables** - click to check that the CDC flow can run against the configured source database and tables.  
    Learn more in [Verify tables](#verify-tables) below.
12. Click **Save task configuration** to save the task once you've finished configuring all tables and their advanced settings.
    Studio may first verify the configuration against the source database.  
    Learn more in [Save the task configuration](#save-the-task-configuration) below.
13. Click **Test** to preview the mapping output before saving.

---

### Add missing root tables

When a linked table references a source table that is not configured as a root table,
Studio displays a warning above the configured tables.

The parent document will contain the linked document ID,
but CDC Sink will not create the referenced document until the source table is also configured as a root table.

![Missing root table warning](https://docs.ravendb.net/assets/images/create-task-6.1-5cf94795884f34753801e845c985e749.png)

1. **Missing root table warning**  
   Indicates how many referenced source tables are not configured as root tables.
2. **Add root table**  
   Click to open the **Add root tables** dialog.

![Add root tables](https://docs.ravendb.net/assets/images/create-task-6.2-d0c6d675ec7bb6e2055be2155a072b3b.png)

1. Select the source tables that you want to configure as root tables.  
   Studio selects all missing tables by default.
2. Click **Add 1 root table** (or **Add *n* root tables** when multiple tables are selected).

Studio adds the selected tables to the configuration as root tables.  
Review the generated mappings, then click **Save task configuration** to save the changes.

---

### Configure linked tables

A **linked table** turns a foreign-key relationship into a document-ID reference:
instead of copying the related row's data into the document,
the parent document stores a reference (a document ID) to a document in another collection.

![Add a linked table](https://docs.ravendb.net/assets/images/create-task-7.0-98f5235f3edd835ce16f44ebeb579c6c.png)

1. On a root (or embedded) table in the **Tables** list, click the three-dots **Table actions** icon.
2. Select **Add new linked table**.

---

In this example, the `customers` table is linked under the `orders` root table.  
The resulting Order document gets a `Customer` property holding a document-ID reference into the `Customers` collection.

![Linked table mapping](https://docs.ravendb.net/assets/images/create-task-7-08f9fb32b5ca5cb8f5249f5e61ad70b9.png)

1. **The source table that is linked**
2. **Source schema**  
   The related source schema.
3. **Source table**  
   The related source table.
4. **Target property**  
   The RavenDB document field that will hold the reference to the linked (related) document.
5. **Linked collection**  
   The RavenDB collection the reference points to.  
   Its name is combined with the join column value(s) to form the referenced document ID  
   (e.g. `Customers` + `customer_id` → `Customers/1`).
6. **Join columns**  
   The foreign key column(s) used to join this linked table to the parent table.  
   Their values, combined with the linked collection name, form the related document ID.  
   Click **Add join column** for a composite key.

---

### Configure embedded tables

An **embedded table** nests the related rows *inside* the parent document instead of referencing them.

![Add an embedded table](https://docs.ravendb.net/assets/images/create-task-8-86aba45db2e52f6e12bda91995e5948f.png)

1. On a root (or embedded) table in the **Tables** list, click the three-dots **Table actions** icon.
2. Select **Add new embedded table**.

---

![Embedded table mapping](https://docs.ravendb.net/assets/images/create-task-9-91519ed803017a8296f31424aaf5733d.png)

1. The embedded table appears nested under its parent in the **Tables** list (marked with `{+}`).
2. **Source schema**  
   The schema of the related source table (e.g. `public`).
3. **Source table**  
   The related source table (e.g. `customers`).
4. **Target property**  
   The RavenDB document field where the embedded related data will be stored.
5. **Relation type**  
   How related rows are embedded in the parent document:
   - `Array` - multiple rows stored as an array of objects
   - `Map` - multiple rows stored as a keyed object (dictionary)
   - `Value` - a single row stored directly as an object
6. **Primary key columns**  
   Columns that uniquely identify rows in this related table.
7. **Join columns**  
   Columns used to match rows in this related table with rows from the root table.
8. **Field mapping**  
   Map the related table's columns to document properties,  
   each with its own **Type** (Default / JSON / Attachment).

---

### Test mapping

![Test mapping panel](https://docs.ravendb.net/assets/images/create-task-10-007739fe23cf647c5515d7db7e851c1d.png)

1. Select the table whose mapping you want to test.
2. Click **Test** to open the test panel.
3. The **Test mapping** panel shows the selected table-to-collection mapping (e.g. `customers` → `Customers`).
4. **Settings**
   - **Row selector**  
     Choose which source rows to pull for the test:
     - `First row`  
       Fetch rows from the top of the table.  
       Set **Max rows** to control how many rows to fetch and preview.  
       Each fetched row is turned into a RavenDB document, so you can preview **multiple** documents at once.
     - `Primary key`  
       Fetch a **single** specific row by entering its primary key value(s).  
       For a composite primary key, enter one value per key column - together they identify one row.
   - **Simulate on delete**  
     Run the test as if the rows were DELETE events instead of inserts/updates,  
     to preview your delete handling (Skip deletion / Delete patch).
5. Click **Run test** to execute the test against the source data.
6. The resulting RavenDB document(s) are shown as **JSON**.

Test mapping previews the documents produced from the selected table's rows.  
It does not check whether the source database is ready for CDC, see [Verify tables](#verify-tables).

---

### Advanced settings

![Patch and delete settings](https://docs.ravendb.net/assets/images/create-task-11-bfb6749da2a4f31199bf78829a2a172f.png)

1. Expand **Advanced settings** for the selected table.
2. **Case sensitive keys**  
   This option is shown only for **embedded tables**.  
   For `Array` and `Map` embedded tables, it controls whether string primary-key values are matched case-sensitively when locating items within the parent document.  
   Enable it when values that differ only by letter case represent different keys. Default: off.
3. **Patch**  
   An optional script that transforms `this` (the document) AFTER column mapping, on INSERT and UPDATE events.
4. **Patch syntax help**  
   Click the **(?)** icon for patch syntax help and examples.
5. **Skip deletion**  
   Enable to ignore source DELETE events (useful for soft-delete scenarios).
6. **Delete patch**  
   An optional script that runs on DELETE events BEFORE the delete is applied or ignored.
7. **Delete-patch syntax help**  
   Click the **(?)** icon for delete-patch syntax help and examples.

---

### Verify tables

![Verify tables](https://docs.ravendb.net/assets/images/create-task-13-1ec0f34487fc89fbd70065f6b0978585.png)

Use **Verify tables** to check that the CDC flow can run against the live source database for the configured connection string and tables
before you save the task.

- Verification runs the same source-side setup and initial-load steps the task runs when it starts,  
  but reads at most one row from each configured table and does not stream changes.  
  It reads these rows even if **Skip initial load** is enabled.
- Verification does **not** create the task, and does not write documents, checkpoints, or task state to RavenDB.
- When verification completes, it attempts to remove the CDC objects it created on the source database.  
  If cleanup fails, verification reports a warning.  
  Which objects are created depends on the source database, see
  [PostgreSQL](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/prerequisites-checklist.md#check-prerequisites-with-verify-tables),
  [SQL Server](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/sql-server/overview.md#table-verification),
  or [MySQL/MariaDB](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/mysql/overview.md#table-verification).
- Disabled tables are not verified,
  see [Enable/Disable a configured table](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/enable-disable-task.md#enable-disable-a-configured-table-via-studio).
- The RavenDB node you are connected to in Studio performs the verification.  
  The CDC Sink task may run on a different node.

When you click **Verify tables**, the button shows *"Verifying tables..."* while verification runs, and then the result:

- **Tables verified** - verification completed without errors or warnings.

  ![Tables verified](https://docs.ravendb.net/assets/images/create-task-14-9da7b37c8300b8ab3980e3bf91971943.png)

- **Tables verified with warnings** - verification completed and reported warnings.  
  Warnings describe conditions the task may run into, or will handle itself, when it starts.  
  Warnings do not prevent saving the task.

  ![Missing publication tables](https://docs.ravendb.net/assets/images/create-task-15-9d098bcb0bbaeb61ad6d3a57344705b1.png)

- **Verification failed** - verification stopped at the first error.  
  After fixing it, click **Verify tables** again to check for further errors.

  ![Missing source column](https://docs.ravendb.net/assets/images/create-task-16-318a54952ea9475df476182d28dd3e5c.png)

  The error message describes what failed.  
  Errors about setting up CDC objects may include a command an administrator can run to fix the problem.  
  Click **Show details**, when available, to view the full error, including the stack trace.

The result applies to the connection string selection, PostgreSQL publication and slot names, and table configuration.  
Changing any of them resets the button to **Verify tables**.

To interpret the result, see [Troubleshooting: 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).

---

### Save the task configuration

Click **Save task configuration** to save the task.

Before saving, Studio verifies the configuration if:

- the task is new, or
- the connection string selection, the PostgreSQL publication or slot name, or the table configuration has changed since the task was last saved.

If a verification result is already available for the current configuration, Studio uses it instead of verifying again.  
This applies to results from **Verify tables** or an earlier save attempt, including results with warnings or a verification error.

If verification completes without warnings, the task is saved.  
If verification reports warnings or fails, Studio asks you to confirm:

![Save anyway confirmation](https://docs.ravendb.net/assets/images/create-task-17-f66507c44999ae85859b050b276b7ec7.png)

- Click **Save anyway** to save the task configuration despite the warnings or error.  
  The task may encounter the same problem when it starts.
- Click **Cancel** to return to the configuration without saving.

If the verification request itself fails, for example because of a network error,  
Studio shows it as a failed verification (*"The dry run request failed. Check the Notification Center for details."*).  
A failed request is not reused as a verification result, so Studio verifies again on save when verification is required.  
If that request also fails, you can still save with **Save anyway**.

---

### The created task

![Created CDC Sink task](https://docs.ravendb.net/assets/images/create-task-12-030cf32f970be0224a780c683c4de9f3.png)

1. The new task appears under **Ongoing Tasks**.
2. It is listed under the **SINK (SOURCE ⇒ RavenDB)** group, showing the task name, its responsible node, and its state.  
   Use the controls on the right to enable/disable, edit, or delete the task.

## Create a CDC Sink task via REST API {#create-a-cdc-sink-task-via-rest-api}

### Discover the source database schema

Use this endpoint to list tables, columns, primary keys, and foreign keys from the source database.  
Use the returned schema metadata to build the `Tables` section of the `CdcSinkConfiguration` before sending the create-task request.

The request body should include either:

- `ConnectionStringName`, to use a saved SQL connection string, or
- `Connection`, to pass an inline `SqlConnectionString`.

For PostgreSQL, you can include `Schemas` to limit schema discovery (defaults to `["public"]`).

| Method | Endpoint | Auth |
| - | - | - |
| `POST` | `/databases/{databaseName}/admin/cdc-sink/schema` | `DatabaseAdmin` |

### Verify the configuration

Use this endpoint to run the CDC flow once against the source database before creating or updating the task,  
as **Verify tables** does in Studio.  
It does not create the task, and does not write documents, checkpoints, or task state to RavenDB.

The request body should include:

- `Configuration` - the `CdcSinkConfiguration` to verify. `Name` is not required.
- `Connection` - the `SqlConnectionString` of the source database, passed inline.  
  This endpoint does not resolve `ConnectionStringName`.

The response includes:

- `Success` - `true` if verification completed without an error. Warnings do not affect this value.
- `Error` - the full text of the error that stopped verification, or `null`.
- `Warnings` - conditions reported during verification, including source cleanup failures.
- `CompletedTables` - the configured tables, as `schema.table`, whose initial-load step completed, including empty tables.

Verification uses a two-minute timeout that is refreshed as it reads the configured tables.  
The total request can take longer, including source cleanup.

| Method | Endpoint | Auth |
| - | - | - |
| `POST` | `/databases/{databaseName}/admin/cdc-sink/dry-run` | `DatabaseAdmin` |

### Create the task

Send a `PUT` request whose body is the JSON `CdcSinkConfiguration`.  
Omit the `id` query-string parameter to create a new task; the response returns the assigned `TaskId`.

| Method | Endpoint | Auth |
| - | - | - |
| `PUT` | `/databases/{databaseName}/admin/cdc-sink` | `DatabaseAdmin` |

## See also

- [Configuration Reference](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/configuration-reference.md)
- [Update a Task](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/update-task.md)
- [Overview](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/overview.md)
- [What are Operations](https://docs.ravendb.net/7.2/client-api/operations/what-are-operations.md)
