> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Change Data Capture Overview

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

**Change data capture (CDC)** detects row-level data changes in CockroachDB and emits those changes as messages for downstream processing. While CockroachDB is an excellent system of record, CDC allows it to integrate with other systems in your data ecosystem.

For example, you might want to:

* Stream messages to Kafka to trigger notifications in an application.
* Mirror your data in full-text indexes, analytics engines, or big data pipelines.
* Export a snapshot of tables to backfill new applications.
* Feed updates to data stores powering machine learning models.

The main feature of CockroachDB CDC is the *changefeed*, which targets an allowlist of tables, known as *watched tables*.

## Stream row-level changes with changefeeds

Changefeeds are customizable *jobs* that monitor row-level changes in a table and emit updates in real time. These updates are delivered in your preferred format to a specified destination, known as a *sink*.

In production, changefeeds are typically configured with an external sink such as Kafka or cloud storage. However, for development and testing purposes, *sinkless changefeeds* allow you to stream change data directly to your SQL client.

Each emitted row change is delivered at least once, and the first emit of every event for the same key is ordered by timestamp.

|                            | Sinkless changefeeds                                                                                         | Changefeeds                                                                                                                                                                                                                                        |
| -------------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Use case**               | Useful for prototyping or quick testing.                                                                     | Recommended for production use.                                                                                                                                                                                                                    |
| **Product availability**   | All products                                                                                                 | All products                                                                                                                                                                                                                                       |
| **Message delivery**       | Streams indefinitely until underlying SQL connection is closed.                                              | Maintains connection to configured <InternalLink path="changefeed-sinks">sink</InternalLink>.                                                                                                                                                      |
| **SQL statement**          | Create with <InternalLink path="create-changefeed">`CREATE CHANGEFEED FOR TABLE table\_name;`</InternalLink> | Create with <InternalLink path="create-changefeed">`CREATE CHANGEFEED FOR TABLE table\_name INTO 'sink';`</InternalLink>                                                                                                                           |
| **Targets**                | Watches one or multiple tables in a comma-separated list.                                                    | Watches one or multiple tables in a comma-separated list.                                                                                                                                                                                          |
| **Filter change data**     | Use <InternalLink path="cdc-queries">CDC queries</InternalLink> to define the emitted change data.           | Use <InternalLink path="cdc-queries">CDC queries</InternalLink> to define the emitted change data.                                                                                                                                                 |
| **Schedule changefeeds**   | Not supported                                                                                                | Create a scheduled changefeed with <InternalLink path="create-schedule-for-changefeed">`CREATE SCHEDULE FOR CHANGEFEED`</InternalLink>.                                                                                                            |
| **Job execution locality** | Not supported                                                                                                | Use <InternalLink path="changefeeds-in-multi-region-deployments#run-a-changefeed-job-by-locality">`execution\_locality`</InternalLink> to determine the node locality for changefeed job execution.                                                |
| **Message format**         | Emits every change to a "watched" row as a record to the current SQL session.                                | Emits every change to a "watched" row as a record in a <InternalLink path="changefeed-messages#message-formats">configurable format</InternalLink>.                                                                                                |
| **Management**             | Create the changefeed and cancel by closing the SQL connection.                                              | <InternalLink path="create-and-configure-changefeeds">Manage changefeed</InternalLink> with `CREATE`, `PAUSE`, `RESUME`, `ALTER`, and `CANCEL`.                                                                                                    |
| **Monitoring**             | Not supported                                                                                                | <InternalLink path="monitor-and-debug-changefeeds">Metrics</InternalLink> available to monitor in the DB Console and Prometheus. Job observability with <InternalLink path="show-jobs#show-changefeed-jobs">`SHOW CHANGEFEED JOBS`</InternalLink>. |

## Get started with changefeeds

To get started with changefeeds in CockroachDB, refer to:

* <InternalLink path="create-and-configure-changefeeds">Create and Configure Changefeeds</InternalLink>: Learn about the fundamentals of using SQL statements to create and manage changefeeds.
* <InternalLink path="changefeed-sinks">Changefeed Sinks</InternalLink>: The downstream system to which the changefeed emits changes. Learn about the supported sinks and configuration capabilities.
* <InternalLink path="changefeed-messages">Changefeed Messages</InternalLink>: The change events that emit from the changefeed. Learn about how messages are ordered and the options to configure and format messages.
* <InternalLink path="changefeed-examples">Changefeed Examples</InternalLink>: Step-by-step examples for connecting to changefeed sinks or running sinkless changefeeds.

### Authenticate to your changefeed sink

To send changefeed messages to a sink, it is necessary to provide the `CREATE CHANGEFEED` statement with authentication credentials.

The following pages detail the supported authentication:

| Sink                 | Authentication page                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Cloud Storage        | Refer to <InternalLink path="cloud-storage-authentication">Cloud Storage Authentication</InternalLink> for detail on setting up:<ul><li>IAM roles with assume role authentication.</li><li>Workload identity authentication.</li><li>Implicit authentication.</li><li>Specified authentication.</li></ul>                                                                                                                                                                                                                                                                                                                 |
| Kafka                | Refer to:<ul><li><InternalLink path="connect-to-a-changefeed-kafka-sink-with-oauth-using-okta">Connect to a Changefeed Kafka Sink with OAuth Using Okta</InternalLink> to connect to your Kafka sink using OAuth authentication.</li><li><InternalLink path="stream-a-changefeed-to-a-confluent-cloud-kafka-cluster">Stream a Changefeed to a Confluent Cloud Kafka Cluster</InternalLink> to authenticate to a Confluent Cloud Kafka cluster with a Confluent Schema Registry.</li><li><InternalLink path="changefeed-sinks#kafka">Query parameters</InternalLink> to supply your own certificate credentials.</li></ul> |
| Webhook              | Refer to:<ul><li><InternalLink path="changefeed-sinks#webhook-sink">Query parameters</InternalLink> to supply your own certificate credentials.</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Google Cloud Pub/Sub | Refer to:<ul><li><InternalLink path="changefeed-sinks">Query parameters</InternalLink> for a general list of the supported query parameters.</li><li><InternalLink path="cloud-storage-authentication?filters=gcs#set-up-google-cloud-storage-assume-role">Cloud Storage Authentication</InternalLink> for detail on IAM roles with assume role authentication.</li></ul>                                                                                                                                                                                                                                                 |

## Monitor your changefeed job

It is a best practice to monitor your changefeed jobs for behavior such as failures and retries.

You can use the following tools for monitoring:

* The <InternalLink path="ui-cdc-dashboard">Changefeed Dashboard</InternalLink> on the DB Console
* The <InternalLink path="show-jobs#show-changefeed-jobs">`SHOW CHANGEFEED JOBS`</InternalLink> statement
* <InternalLink path="monitor-and-debug-changefeeds#using-changefeed-metrics-labels">Changefeed metrics labels</InternalLink>

Refer to the <InternalLink path="monitor-and-debug-changefeeds">Monitor and Debug Changefeeds</InternalLink> page for recommendations on metrics to track.

For detail on how protected timestamps and garbage collection interact with changefeeds, refer to <InternalLink path="protect-changefeed-data">Protect Changefeed Data from Garbage Collection</InternalLink>.

## Optimize a changefeed for your workload

### Filter your change data with CDC queries

*Change data capture queries* allow you to define and filter the change data emitted to your sink when you create an changefeed.

For example, you can use CDC queries to:

* <InternalLink path="cdc-queries#filter-columns">Filter out rows and columns</InternalLink> from changefeed messages to decrease the load on your downstream sink.
* <InternalLink path="cdc-queries#customize-changefeed-messages">Modify data before it emits</InternalLink> to reduce the time and operational burden of filtering or transforming data downstream.
* <InternalLink path="cdc-queries#stabilize-the-changefeed-message-schema">Stabilize or customize the schema</InternalLink> of your changefeed messages for increased compatibility with external systems.

Refer to the <InternalLink path="cdc-queries">Change Data Capture Queries</InternalLink> page for more example use cases.

### Use changefeeds to export a table

Changefeeds can export a single table scan to your sink. The benefits of using changefeeds for exports include: job management, observability, and sink configurability. You can also schedule changefeeds to export tables, which may be useful to avoid table scans during peak periods.

For examples and more detail, refer to:

* <InternalLink path="export-data-with-changefeeds">Export Data with Changefeeds</InternalLink>
* <InternalLink path="create-schedule-for-changefeed">`CREATE SCHEDULE FOR CHANGEFEED`</InternalLink>

### Determine the nodes running a changefeed by locality

CockroachDB supports an option to set locality filter requirements that nodes must meet in order to take part in a changefeed job. This is helpful in multi-region clusters to ensure the nodes that are physically closest to the sink emit changefeed messages. For syntax and further technical detail, refer to <InternalLink path="changefeeds-in-multi-region-deployments#run-a-changefeed-job-by-locality">Run a changefeed job by locality</InternalLink>.
