Skip to main content
Changefeeds emit messages to configurable downstream sinks. This page details the URIs, parameters, and configurations available for each changefeed sink. CockroachDB supports the following sinks: For a guide to using changefeeds with Amazon Simple Notification Service (Amazon SNS), refer to this blog that uses the webhook sink with Amazon API Gateway to publish messages to Amazon SNS. The page provides detail on using the SQL statement and a complete list of the and options available when setting up a changefeed. For a step-by-step example connecting a changefeed to a sink, see the page.

Sink URI

The sink URI follows the basic format of:
You can create an external connection to represent a changefeed sink URI. This allows you to specify the external connection’s name in statements rather than the provider-specific URI. For detail on using external connections, see the page. To set a different sink URI to an existing changefeed, use the with ALTER CHANGEFEED.
Cockroach Labs recommends enabling Egress Perimeter Controls on CockroachDB Advanced clusters to mitigate the risk of data exfiltration when accessing external resources, such as cloud storage for change data capture or backup and restore operations. See for detail and setup instructions.

Kafka

Kafka sink connection

Example of a Kafka sink URI using SCRAM-SHA-256 authentication:
Example of a Kafka sink URI using OAUTHBEARER authentication:
OAuth 2.0 authentication uses credentials managed by a third-party provider (IdP) to authenticate with Kafka instead of requiring you to provide your Kafka cluster credentials directly in a statement. Your provider’s authentication server will issue a temporary token, giving you flexibility to apply access rules on the credentials that your IdP provides. To authenticate to Kafka with OAuth using Okta, see the tutorial. and in CockroachDB Advanced clusters do not support connecting to a sink’s internal IP addresses for . To connect to a Kafka sink from CockroachDB Advanced, it is necessary to expose the Kafka cluster’s external IP address and open ports with firewall rules to allow access from a CockroachDB Advanced cluster. The following table lists the available parameters for Kafka URIs: This table shows the parameters for changefeeds to a specific sink. The CREATE CHANGEFEED page provides a list of all the available .

Topic naming

By default, a Kafka topic has the same name as the table on which a changefeed was created. If you create a changefeed on multiple tables, the changefeed will write to multiple topics corresponding to those table names. When you run CREATE CHANGEFEED to a Kafka sink, the output will display the job ID as well as the topic name(s) that the changefeed will emit to. To modify the default topic naming, you can specify a , , or use the . Using the parameter, you can specify an arbitrary topic name and feed all tables into that topic. You can either manually create a topic in your Kafka cluster before starting the changefeed, or the topic will be automatically created when the changefeed connects to your Kafka cluster.
You must have the Kafka cluster setting auto.create.topics.enable set to true for automatic topic creation. This will create the topic when the changefeed sends its first message. If you create the consumer before that, you will also need the Kafka consumer configuration allow.auto.create.topics to be set to true.
Kafka has the following topic limitations:
  • Legal characters are numbers, letters, and [._-].
  • The maximum character length of a topic name is 249.
  • Topics with a period ( . ) and underscore ( _ ) can collide on internal Kafka data structures, so you should use either but not both.
  • Characters not accepted by Kafka will be automatically encoded as unicode characters by CockroachDB.

Kafka sink configuration

You can configure flushing, acknowledgments, compression, and concurrency behavior of changefeeds running to a Kafka sink with the following:
  • Set the to configure the number of concurrent workers used by changefeeds in the cluster when sending requests to a Kafka sink. When you set changefeed.sink_io_workers, it will not affect running changefeeds; , set changefeed.sink_io_workers, and then . changefeed.sink_io_workers will also affect changefeeds running to Google Cloud Pub/Sub sinks and webhook sinks.
changefeed.sink_io_workers only applies to Kafka sinks created in v24.2.1+, or if the changefeed.new_kafka_sink.enabled cluster setting has been enabled in CockroachDB clusters running v23.2.10+ and v24.1.4+.
  • The kafka_sink_config option allows configuration of a changefeed’s message delivery, Kafka server version, and batching parameters.
Each of the following settings have significant impact on a changefeed’s behavior, such as latency. For example, it is possible to configure batching parameters to be very high, which would negatively impact changefeed latency. As a result it would take a long time to see messages coming through to the sink. Also, large batches may be rejected by the Kafka server unless it’s separately configured to accept a high max.message.bytes.
Using the default values or not setting fields in kafka_sink_config will mean that changefeed messages emit immediately. The configurable fields are as follows:

ClientID

Implement a Kafka resource usage limit per changefeed by setting a client ID and Kafka quota. You can set the quota for the client ID in your Kafka server’s configuration:
When you create a changefeed, include the "ClientID" field with the unique client ID (e.g., kafka_client_ID_1) you have configured in your Kafka server configuration. This will subject the changefeed to the Kafka quota applied to that client ID. We recommend tracking the to monitor the time spent throttling due to changefeed messages exceeding Kafka quotas. For details on setting quotas to client IDs, refer to the Kafka documentation.

CompressionLevel

The CompressionLevel field allows you to implement a level of compression for your set Compression protocol. CompressionLevel determines the level of the compression ratio versus the compression speed. That is, how much the data is reduced for better compression and how quickly the compression is completed for faster compression. The compression protocols support the following values:
  • GZIP:
    • -2: Huffman-only compression
    • -1: Default compression
    • 0: No compression
    • 1 to 9: From fastest compression to best compression
  • ZSTD:
    • 1: Fastest compression
    • 2: Default compression
    • 3: Better compression
    • 4: Best compression
  • LZ4: The supported values from fastest compression to best compression:
    • 0: Fastest compression (Default)
    • 512
    • 1024
    • 2048
    • 4096
    • 8192
    • 16384
    • 32768
    • 65536
    • 131072: Best compression If you have the changefeed.new_kafka_sink.enabled cluster setting disabled, CompressionLevel will not affect LZ4 compression.
  • SNAPPY does not support the CompressionLevel field.

Flush

"Flush"."MaxMessages" and "Flush"."Frequency" are configurable batching parameters depending on latency and throughput needs. For example, if "MaxMessages" is set to 1000 and "Frequency" to 1 second, it will flush to Kafka either after 1 second or after 1000 messages are batched, whichever comes first. It’s important to consider that if there are not many messages, then a "1s" frequency will add 1 second latency. However, if there is a larger influx of messages these will be flushed quicker.

RequiredAcks

The RequiredAcks field defines what a successful write to Kafka is. The possible values are:
  • "ONE": A write to Kafka is successful once the leader node has committed and acknowledged the write. Note that this has the potential risk of dropped messages; if the leader node acknowledges before replicating to a quorum of other Kafka nodes, but then fails.
  • "NONE": No Kafka brokers are required to acknowledge that they have committed the message. This will decrease latency and increase throughput, but comes at the cost of lower consistency.
  • "ALL": A quorum must be reached (that is, most Kafka brokers have committed the message) before the leader can acknowledge. This is the highest consistency level. You must also set acks to ALL in your server-side Kafka configuration for this to provide high durability delivery.

Kafka sink messages

The following shows the messages for a changefeed emitting to Kafka:
See the page and the tutorial for examples to set up a Kafka sink. For an overview of the messages emitted from changefeeds, see the page.

Amazon MSK

On CockroachDB self-hosted clusters, you must create instances in the same VPC as the MSK or MSK Serverless cluster in order for the changefeed to authenticate successfully.If you would like to connect a CockroachDB Advanced cluster to an Amazon MSK cluster, contact your Cockroach Labs account team.
Changefeeds can deliver messages to Amazon MSK clusters (Amazon Managed Streaming for Apache Kafka). Amazon MSK cluster types include: MSK and MSK Serverless. Changefeeds support the following authentication methods for these MSK cluster types:
  • MSK: SCRAM or IAM
  • MSK Serverless: IAM
Changefeeds can deliver messages to MSK and MSK Serverless clusters using AWS IAM roles. For initial setup guides, refer to the AWS documentation: Changefeeds connecting to Amazon MSK clusters use the kafka:// scheme. The example URIs show the necessary parameters for MSK and MSK Serverless clusters depending on the authentication type:
  • To connect to an MSK cluster using SCRAM authentication, you must include the following parameters in the URI:
    For SCRAM authentication, add your SASL username and password to the URI.
  • To connect to an MSK or MSK Serverless cluster using AWS IAM roles, you must include the following parameters in the URI:
    For IAM authentication, add the MSK cluster region, IAM role ARN, and session name to the URI.
This table outlines the available parameters for Amazon MSK URIs: For more detail on each of these parameters, refer to .

Confluent Cloud

Changefeeds can deliver messages to Kafka clusters hosted on Confluent Cloud. A Confluent Cloud sink connection URI must include the following:
The api_key and api_secret are the required parameters for the Confluent Cloud sink connection URI. Changefeeds emitting to a Confluent Cloud Kafka cluster support the standard Kafka parameters, such as topic_name and topic_prefix. Confluent Cloud sinks also support the standard Kafka and the Kafka sink configuration option. For a Confluent Cloud setup example, refer to the page. The following parameters are also needed, but are set by default in CockroachDB:
  • tls_enabled=true
  • sasl_enabled=true
  • sasl_handshake=true
  • sasl_mechanism=PLAIN

Google Cloud Pub/Sub

Changefeeds can deliver messages to a Google Cloud Pub/Sub sink, which is integrated with Google Cloud Platform.
Since CockroachDB v23.2, the changefeed.new_pubsub_sink_enabled cluster setting is enabled by default, which provides improved throughput. Without this cluster setting enabled, changefeeds emit JSON-encoded events with the top-level message fields all lowercase. With changefeed.new_pubsub_sink_enabled, the top-level fields are capitalized. For more details, refer to the Pub/Sub sink messages section.
A Pub/Sub sink URI follows this example:
This table shows the parameters for changefeeds to a specific sink. The CREATE CHANGEFEED page provides a list of all the available . When using Pub/Sub as your downstream sink, consider the following:
  • Pub/Sub sinks support JSON message format. You can use the option in combination with for CSV-formatted messages.
  • Use the option for multi-region Pub/Sub. Google Cloud’s multi-region Pub/Sub will have lower latency when emitting from multiple regions, but Google Cloud Pub/Sub does not support message ordering for multi-region topics.
  • Changefeeds connecting to a Pub/Sub sink do not support the topic_prefix option.
Ensure one of the following Pub/Sub roles are set in your Google Service Account at the project level:
  • To create topics on changefeed creation, you must use the Pub/Sub Editor role, which contains the permissions to create a topic.
  • If the topic the changefeed is writing to already exists, then you can use the more limited Pub/Sub Publisher role, which can only write to existing topics.
For more information, read about compatible changefeed and the example.
You can use Google’s Pub/Sub emulator, which allows you to run Pub/Sub locally for testing. CockroachDB uses the Google Cloud SDK, which means that you can follow Google’s instructions for Setting environment variables to run the Pub/Sub emulator.

Pub/Sub topic naming

When running a CREATE CHANGEFEED statement to a Pub/Sub sink, consider the following regarding topic names:
  • Changefeeds will try to create a topic automatically. When you do not specify the topic in the URI with the parameter, the changefeed will use the table name to create the topic name.
  • If the topic already exists in your Pub/Sub sink, the changefeed will write to it.
  • Changefeeds watching multiple tables will write to multiple topics corresponding to those table names.
  • The option will create a topic using the fully qualified table name for each table the changefeed is watching.
  • The output from CREATE CHANGEFEED will display the job ID as well as the topic name(s) to which the changefeed will emit.
You can manually create a topic in your Pub/Sub sink before starting the changefeed. Refer to the example for more detail. To understand restrictions on user-specified topic names, refer to Google’s documentation on Guidelines to name a topic or subscription. For a list of compatible parameters and options, refer to on the CREATE CHANGEFEED page.

Pub/Sub sink configuration

You can configure flushing, retry, and concurrency behavior of changefeeds running to a Pub/Sub sink with the following:
  • Set the to configure the number of concurrent workers used by changefeeds in the cluster when sending requests to a Pub/Sub sink. When you set changefeed.sink_io_workers, it will not affect running changefeeds; , set changefeed.sink_io_workers, and then . Note that this cluster setting will also affect changefeeds running to webhook sinks and Kafka.
  • Set the pubsub_sink_config option to configure the changefeed flushing and retry behavior to your webhook sink. For details on the pubsub_sink_config option’s configurable fields, refer to the following table and examples.
For example:
Setting either Messages or Bytes with a non-zero value without setting Frequency will cause the sink to assume Frequency has an infinity value. If either Messages or Bytes have a non-zero value, then a non-zero value for Frequency must be provided. This configuration is invalid and will cause an error, since the messages could sit in a batch indefinitely if the other conditions do not trigger.
Some complexities to consider when setting Flush fields for batching:
  • When all batching parameters are zero ("Messages", "Bytes", and "Frequency") the sink will interpret this configuration as “send batch every time a message is available.” This would be the same as not providing any configuration at all:
  • If one or more fields are set as non-zero values, any fields with a zero value the sink will interpret as infinity. For example, in the following configuration, the sink will send a batch whenever the size reaches 100 messages, or, when 5 seconds has passed since the batch was populated with its first message. Bytes is unset, so the batch size is unlimited. No flush will be triggered due to batch size:

Pub/Sub sink messages

The changefeed.new_pubsub_sink_enabled cluster setting is enabled by default, which provides improved changefeed throughput peformance. With changefeed.new_pubsub_sink_enabled enabled, the changefeed JSON-encoded message format have top-level fields that are capitalized:
By default in v23.2, the capitalization of top-level fields in the message has changed. Before upgrading to CockroachDB v23.2 and later, you may need to reconfigure downstream systems to parse the new message format.
With changefeed.new_pubsub_sink_enabled set to false, changefeeds emit JSON messages with the top-level fields all lowercase:
If changefeed.new_pubsub_sink_enabled is set to false, changefeeds will not benefit from the improved throughput performance that this setting enables. The following shows the default JSON messages for a changefeed emitting to Pub/Sub. These changefeed messages were emitted as part of the example:
For an overview of the messages emitted from changefeeds, see the page.

Cloud storage sink

Use a cloud storage sink to deliver changefeed data to OLAP or big data systems without requiring transport via Kafka. Some considerations when using cloud storage sinks:
  • Cloud storage sinks work with JSON and emit newline-delimited JSON files. You can use the option in combination with for CSV-formatted messages.
  • Cloud storage sinks can be configured to store emitted changefeed messages in one or more subdirectories organized by date. See file partitioning and the examples.
  • The supported cloud schemes are: s3, gs, azure, http, and https.
  • Both http:// and https:// are cloud storage sinks, not webhook sinks. It is necessary to prefix the scheme with webhook- for webhook sinks.
You can authenticate to cloud storage sinks using specified or implicit authentication. CockroachDB also supports assume role authentication for Amazon S3 and Google Cloud Storage, which allows you to limit the control specific users have over your storage buckets. For detail and instructions on authenticating to cloud storage sinks, see . Examples of supported cloud storage sink URIs:

Amazon S3

Azure Blob Storage

Google Cloud Storage

HTTP

Cloud storage parameters

The following table lists the available parameters for cloud storage sink URIs: This table shows the parameters for changefeeds to a specific sink. The CREATE CHANGEFEED page provides a list of all the available . provides more detail on authentication to cloud storage sinks.

Cloud storage sink messages

The following shows the default JSON messages for a changefeed emitting to a cloud storage sink:
For an overview of the messages emitted from changefeeds, see the page.

Webhook sink

Use a webhook sink to deliver changefeed messages to an arbitrary HTTP endpoint. Example of a webhook sink URL:
The following table lists the parameters you can use in your webhook URI: This table shows the parameters for changefeeds to a specific sink. The CREATE CHANGEFEED page provides a list of all the available . The following are considerations when using the webhook sink:
  • Only supports HTTPS. Use the parameter when testing to disable certificate verification; however, this still requires HTTPS and certificates.
  • Supports JSON output format. You can use the option in combination with for CSV-formatted messages.

Webhook sink configuration

You can configure flushing, retry, and concurrency behavior of changefeeds running to a webhook sink with the following:
  • Set the to configure the number of concurrent workers used by changefeeds in the cluster when sending requests to a webhook sink. When you set changefeed.sink_io_workers, it will not affect running changefeeds; , set changefeed.sink_io_workers, and then . Note that this cluster setting will also affect changefeeds running to Google Cloud Pub/Sub sinks and Kafka.
  • Set the webhook_sink_config option to configure the changefeed flushing and retry behavior to your webhook sink. For details on the webhook_sink_config option’s configurable fields, refer to the following table and examples.
For example:
Setting either Messages or Bytes with a non-zero value without setting Frequency will cause the sink to assume Frequency has an infinity value. If either Messages or Bytes have a non-zero value, then a non-zero value for Frequency must be provided. This configuration is invalid and will cause an error, since the messages could sit in a batch indefinitely if the other conditions do not trigger. Some complexities to consider when setting Flush fields for batching:
  • When all batching parameters are zero ("Messages", "Bytes", and "Frequency") the sink will interpret this configuration as “send batch every time a message is available.” This would be the same as not providing any configuration at all:
  • If one or more fields are set as non-zero values, any fields with a zero value the sink will interpret as infinity. For example, in the following configuration, the sink will send a batch whenever the size reaches 100 messages, or, when 5 seconds has passed since the batch was populated with its first message. Bytes is unset, so the batch size is unlimited. No flush will be triggered due to batch size:

Webhook sink messages

The following shows the default JSON messages for a changefeed emitting to a webhook sink. These changefeed messages were emitted as part of the example:
For an overview of the messages emitted from changefeeds, see the page.

Azure Event Hubs

Changefeeds can deliver messages to an Azure Event Hub, which is compatible with Apache Kafka. An Azure Event Hubs sink URI:
You can also use a kafka:// scheme in the URI:
The shared_access_key and shared_access_key_name are the required parameters for an Azure Event Hubs connection URI. Changefeeds emitting to an Azure Event hub support topic_name and topic_prefix. Azure Event Hubs also supports the standard Kafka and the Kafka sink configuration option. For an Azure Event Hub setup example, refer to the page. The following parameters are also needed, but are set by default in CockroachDB:
  • tls_enabled=true
  • sasl_enabled=true
  • sasl_handshake=true
  • sasl_mechanism=PLAIN

Apache Pulsar

This feature is in and subject to change. To share feedback and/or issues, contact Support.
Changefeeds can deliver messages to Apache Pulsar. A Pulsar sink URI:
By default, Apache Pulsar listens for client connections on port :6650. For more detail on configuration, refer to the Apache Pulsar documentation. Changefeeds emitting to an Apache Pulsar sink support json and csv . Changefeeds emitting to an Apache Pulsar sink do not support:
  • Any batching configuration
For an Apache Pulsar setup example, refer to the page.

Apache Pulsar sink messages

See also