Skip to main content
The CREATE CHANGEFEED creates a new Enterprise changefeed, which targets an allowlist of tables called “watched rows”. Every change to a watched row is emitted as a record in a configurable format (JSON or Avro) to a . CREATE CHANGEFEED also supports that allow you to filter and transform change data before emitting changefeed messages. You can create, pause, resume, , or cancel an Enterprise changefeed. To get started with changefeeds, refer to the page for important usage considerations. For detail on how changefeeds emit messages, refer to the page. The examples on this page provide the foundational syntax of the CREATE CHANGEFEED statement. For examples on more specific use cases with changefeeds see the following pages:
Cockroach Labs recommends monitoring your changefeeds to track and usage. Refer to the page for more information.

Required privileges

You can a user the CHANGEFEED privilege to allow them to create changefeeds on a specific table:
When you grant a user the CHANGEFEED privilege on a set of tables, they can:
  • Create changefeeds on the target tables even if the user does not have the or the SELECT privilege on the tables.
  • Manage the changefeed jobs running on the tables using the , , , and commands.
These users will be able to create changefeeds, but they will not be able to run a SELECT query on that data directly. However, they could still read this data indirectly if they have read access to the . New in v23.1: To restrict a user’s access to changefeed data and sink credentials, enable the changefeed.permissions.require_external_connection_sink.enabled cluster setting. When you enable this setting, users with the CHANGEFEED privilege on a set of tables can only create changefeeds into external connections . You can add CHANGEFEED to the user or role’s with :

Privilege model

For fine-grained access control, we recommend using the system-level privileges CHANGEFEED and CONTROLJOB / VIEWJOB.
The following summarizes the operations users can run when they have changefeed privileges on a table:

Synopsis

create_changefeed syntax diagram

Parameters

Parameters for change data capture queries

Change data capture queries allow you to define the change data emitted to your sink when you create a changefeed. Refer to the page for detail on the functionality, syntax, and use cases for creating changefeeds that include queries.

Sink URI

This section provides example URIs for each of the sinks that CockroachDB changefeeds support. For more comprehensive detail of using and configuring each sink, refer to the page.
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.

Kafka

Example of a Kafka sink URI:
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.

Google Cloud Pub/Sub

This feature is in and subject to change. To share feedback and/or issues, contact Support.
Example of a Google Cloud Pub/Sub sink URI:
New in v23.1: Enable the changefeed.new_pubsub_sink_enabled to improve the throughput of changefeeds emitting to . Enabling this setting also alters the message format to use capitalized top-level fields in changefeeds emitting JSON-encoded messages to a Pub/Sub sink. For more details, refer to the section.
explains the requirements for the authentication parameter with specified or implicit. Refer to for further consideration.

Cloud Storage

The following are example file URLs for each of the cloud storage schemes: explains the requirements for authentication and encryption for each supported cloud storage sink. Refer to for considerations when using cloud storage.

Webhook

Example of a webhook URI:
New in v23.1: Enable the changefeed.new_webhook_sink_enabled to improve the throughput of changefeeds emitting to webhook sinks. .
Refer to for specifics on webhook sink configuration.

Query parameters

Parameters should always be URI-encoded before they are included in the changefeed’s URI, as they often contain special characters. Use Javascript’s encodeURIComponent function or Go language’s url.QueryEscape function to URI-encode the parameters. Other languages provide similar functions to URI-encode special characters.
Query parameters include: For example: CREATE CHANGEFEED FOR TABLE users INTO 'gs://...?AUTH...&partition_format=hourly'

Default: daily S3_STORAGE_CLASS | | | Specify the Amazon S3 storage class for files created by the changefeed. See Create a changefeed with an S3 storage class for the available classes and an example.

Default: STANDARD New in v23.1: sasl_client_id | | | Client ID for OAuth authentication from a third-party provider. This parameter is only applicable with sasl_mechanism=OAUTHBEARER. New in v23.1: sasl_client_secret | | | Client secret for OAuth authentication from a third-party provider. This parameter is only applicable with sasl_mechanism=OAUTHBEARER. Note: You must base64 encode this value when passing it in as part of a sink URI. sasl_enabled | | | If true, the authentication protocol can be set to SCRAM or PLAIN using the sasl_mechanism parameter. You must have tls_enabled set to true to use SASL.

Default: false New in v23.1: sasl_grant_type | | | Override the default OAuth client credentials grant type for other implementations. This parameter is only applicable with sasl_mechanism=OAUTHBEARER. sasl_mechanism | | | Can be set to OAUTHBEARER, SCRAM-SHA-256, SCRAM-SHA-512, or PLAIN. A sasl_user and sasl_password are required.

See the tutorial for detail setting up OAuth using Okta.

Default: PLAIN New in v23.1: sasl_scopes | | | A list of scopes that the OAuth token should have access for. This parameter is only applicable with sasl_mechanism=OAUTHBEARER. New in v23.1: sasl_token_url | | | Client token URL for OAuth authentication from a third-party provider. Note: You must URL encode this value before passing in a URI. This parameter is only applicable with sasl_mechanism=OAUTHBEARER. sasl_user | | | Your SASL username. sasl_password | | | Your SASL password. Note: Passwords should be URL encoded since the value can contain characters that would cause authentication to fail. tls_enabled | | | If true, enable Transport Layer Security (TLS) on the connection to Kafka. This can be used with a ca_cert (see below).

Default: false topic_name | , | | Allows arbitrary topic naming for Kafka and GC Pub/Sub topics. See the or for detail on supported characters etc.

For example, CREATE CHANGEFEED FOR foo,bar INTO 'kafka://sink?topic_name=all' will emit all records to a topic named all. Note that schemas will still be registered separately. When using Kafka, this parameter can be combined with the topic_prefix parameter (this is not supported for GC Pub/Sub).

Default: table name. topic_prefix | , | | Adds a prefix to all topic names.

For example, CREATE CHANGEFEED FOR TABLE foo INTO 'kafka://...?topic_prefix=bar_' would emit rows under the topic bar_foo instead of foo.

Options

Using the format=avro, envelope=key_only, and updated options together is rejected. envelope=key_only prevents any rows with updated fields from being emitted, which makes the updated option meaningless.

Files

The files emitted to a sink use the following naming conventions:
The timestamp format is YYYYMMDDHHMMSSNNNNNNNNNLLLLLLLLLL.

General file format

For example:
When emitting changefeed messages to a , you can specify a partition format for your files using the partition_format query parameter. This will result in the following file path formats:
  • daily: This is the default option and will follow the same pattern as the previous general file format.
  • hourly: This will partition into an hourly directory as the changefeed emits messages, like the following:
  • flat: This will result in no file partitioning. The cloud storage path you specify when creating a changefeed will store all of the message files with no additional directories created.

Resolved file format

For example:

Examples

Before running any of the examples in this section it is necessary to . If you are working on a CockroachDB Standard or Basic cluster, this cluster setting is enabled by default. The following examples show the syntax for managing changefeeds and starting changefeeds with different use cases and features. The Options table on this page provides a list of all the available options. For information on sink-specific query parameters and configurations, refer to the page. 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. We recommend limiting the number of changefeeds per cluster to 80.

Create a changefeed connected to a sink

You can connect a changefeed to the following sinks:
  • Kafka
  • Cloud storage / HTTP
  • Google Cloud Pub/Sub
  • Webhook
For guidance on the sink URI, refer to:
  • The page for general detail on query parameters and sink configuration.
  • The page for instructions on setting up each supported cloud storage authentication.

Create a changefeed that filters and transforms change data

can filter and transform change data before emitting it to a sink or a SQL client. You can adapt a changefeed with CDC queries by including SELECT and WHERE clauses in your CREATE statement:
CDC queries can only run on a single table per changefeed and require an Enterprise license.

Create a sinkless changefeed

You can create a changefeed that will send messages to the SQL client rather than a sink:
Sinkless changefeeds do not require an Enterprise license; however, a sinkless changefeed with CDC queries does require an Enterprise license. To create a sinkless changefeed using CDC queries:

Use an external connection to specify a changefeed sink

provide a way to define a name for a sink, which you can use instead of the provider-specific URI. New in v23.1: To restrict a user’s access to changefeed data and sink credentials, enable the changefeed.permissions.require_external_connection_sink.enabled cluster setting. When you enable this setting, users with the CHANGEFEED privilege on a set of tables can only create changefeeds into external connections . External connections support all changefeed sinks.
In the changefeed statement, you specify the external connection name:

Disallow schema changes on tables to improve changefeed performance

New in v23.1.15: Use the schema_locked to disallow on a watched table, which helps to decrease the latency between a write committing to a table and it emitting to the . You can lock the table before creating a changefeed or while a changefeed is running, which will enable the performance improvement for changefeeds watching the particular table. Enable schema_locked on the watched table with the statement:
While schema_locked is enabled on a table, attempted schema changes on the table will be rejected and an error returned. If you need to run a schema change on the locked table, unlock the table with schema_locked = false, complete the schema change, and then lock the table again with schema_locked = true. The changefeed will run as normal while schema_locked = false, but it will not benefit from the performance optimization.

Manage a changefeed

For Enterprise changefeeds, use to check the status of your changefeed jobs:
Use the following SQL statements to pause, resume, or cancel a changefeed.

Pause a changefeed

For more information, see .

Resume a paused changefeed

For more information, see .

Cancel a changefeed

For more information, see .

Modify a changefeed

To modify an Enterprise changefeed, the job and then use:
You can add new table targets, remove them, set new , and unset them. For more information, see .

Configuring all changefeeds

It is useful to be able to pause all running changefeeds during troubleshooting, testing, or when a decrease in CPU load is needed. To pause all running changefeeds:
This will change the status for each of the running changefeeds to paused, which can be verified with . To resume all running changefeeds:
This will resume the changefeeds and update the status for each of the changefeeds to running.

Start a new changefeed where another ended

In some situations, you may want to start a changefeed where a previously running changefeed ended. For example, a changefeed could encounter an error it cannot recover from, such as when a , and you need to restart the changefeed.
  1. Use to find the for the ended changefeed:
If a changefeed has failed, you must restart the changefeed from a timestamp after the event that caused the failure.
  1. Use the high_water_timestamp to start the new changefeed:
When you use the cursor option to start a changefeed, it will not perform an initial scan.

Create a changefeed with an S3 storage class

To associate the changefeed message files with a in your Amazon S3 bucket, use the S3_STORAGE_CLASS parameter with the class. For example, the following S3 connection URI specifies the INTELLIGENT_TIERING storage class:
Use the parameter to set one of these storage classes listed in Amazon’s documentation. For more general usage information, see Amazon’s Using Amazon S3 storage classes documentation.

Define a key to determine the changefeed sink partition

New in v23.1: With the key_column option, you can define the key used in message metadata that determines the partition for the changefeed message at your . This option overrides the default :
key_column does not preserve ordering of messages from CockroachDB to the downstream sink, therefore you must include the unordered option. It does not affect per-key or the output of key_in_value.

See also