- Guidelines to consider before creating a changefeed.
- Reference examples for creating and managing a changefeed.
Before you create a changefeed
- Enable rangefeeds on CockroachDB Advanced and CockroachDB self-hosted. Refer to Enable rangefeeds for instructions.
- Decide on whether you will run an Enterprise or basic changefeed. Refer to the page for a comparative capability table.
- Plan the number of changefeeds versus the number of tables to include in a single changefeed for your cluster. We recommend limiting the number of changefeeds per cluster to 80. Refer to System resources and running changefeeds and Recommendations for the number of target tables.
- Consider whether your Enterprise changefeed use case would be better served by that can filter data on a single table. CDC queries can improve the efficiency of changefeeds because the job will not need to encode as much change data.
- Read the Considerations section that provides information on changefeed interactions that could affect how you configure or run your changefeed.
Enable rangefeeds
Changefeeds connect to a long-lived request called a rangefeed, which pushes changes as they happen. This reduces the latency of row changes, as well as reduces transaction restarts on tables being watched by a changefeed for some workloads. Rangefeeds must be enabled for a changefeed to work. To :kv.rangefeed.enabled cluster setting is enabled by default.
Enabling rangefeeds has a small performance cost (about a 5–10% increase in write latencies), whether or not the rangefeed is being used in a changefeed. When kv.rangefeed.enabled is set to true, a small portion of the latency cost is caused by additional write event information that is sent to the and for . The remainder of the latency cost is incurred once a changefeed is running; the write event information is reconstructed and sent to an active rangefeed, which will push the event to the changefeed.
The kv.closed_timestamp.target_duration can be used with changefeeds. Resolved timestamps will always be behind by at least the duration configured by this setting. However, decreasing the duration leads to more transaction restarts in your cluster, which can affect performance.
Recommendations for the number of target tables
When creating a changefeed, it’s important to consider the number of changefeeds versus the number of tables to include in a single changefeed:- Changefeeds each have their own memory overhead, so every running changefeed will increase total memory usage.
- Creating a single changefeed that will watch hundreds of tables can affect the performance of a changefeed by introducing coupling, where the performance of a target table affects the performance of the changefeed watching it. For example, any on any of the tables will affect the entire changefeed’s performance.
System resources and running changefeeds
When you are running more than 10 changefeeds on a cluster, it is important to monitor the . A larger cluster will be able to run more changefeeds concurrently compared to a smaller cluster with more limited resources. We recommend limiting the number of changefeeds per cluster to 80. To maintain a high number of changefeeds in your cluster:- Connect to different nodes to create each changefeed. The node on which you start the changefeed will become the coordinator node for the changefeed job. The coordinator node acts as an administrator: keeping track of all other nodes during job execution and the changefeed work as it completes. As a result, this node will use more resources for the changefeed job. Refer to for more detail.
- Consider logically grouping the target tables into one changefeed. When a changefeed pauses, it will stop emitting messages for the target tables. Grouping tables of related data into a single changefeed may make sense for your workload. However, we do not recommend watching hundreds of tables in a single changefeed. Refer to for more detail on protecting data from garbage collection when a changefeed is paused.
Considerations
- running changefeed jobs before you start a to move to a later version of CockroachDB. For more details, refer to the page.
- If you require message frequency under
30s, then you must set the option to at least the desiredresolvedfrequency. - Many DDL queries (including , , and queries that add a column family) will cause errors on a changefeed watching the affected tables. You will need to . If a table is truncated that a changefeed with
on_error='pause'is watching, you will also need to start a new changefeed. See change data capture for more detail. - Partial or intermittent sink unavailability may impact changefeed stability. If a sink is unavailable, messages can’t send, which means that a changefeed’s high-water mark timestamp is at risk of falling behind the cluster’s . Throughput and latency can be affected once the sink is available again. However, will still hold for as long as a changefeed .
- When an statement is run, any current changefeed jobs targeting that table will fail.
- After you , changefeed jobs will not resume on the new cluster. It is necessary to manually create the changefeeds following the full-cluster restore.
- As of v22.1, changefeeds filter out from events by default. This is a . To maintain the changefeed behavior in previous versions where values are emitted for virtual computed columns, see the option for more detail.
- Changefeeds
- Sinkless changefeeds
Configure a changefeed
An Enterprise changefeed streams row-level changes in a configurable format to a configurable sink (i.e., Kafka or a cloud storage sink). You can create, pause, resume, and cancel an Enterprise changefeed. For a step-by-step example connecting to a specific sink, see the page.Create
To create an Enterprise changefeed, you can either:- Run
CREATE CHANGEFEEDfor one or multiple tables to receive all changes. - Use change data capture queries to run
CREATE CHANGEFEEDon a single table to filter and transform the change data that the changefeed emits.
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.
Run CREATE CHANGEFEED
- All changes to the table data are required with no filtering.
- The are a blocker to how you would process data.
Use change data capture queries
- Filter data to remove unnecessary messages.
- Apply transformations to messages before sending to a sink.
- Minimize any potential impact to the cluster from a changefeed job. For more detail on this, refer to .
Sinkless changefeeds
When you create a changefeed without specifying a sink, CockroachDB sends the changefeed events to the SQL client:- If you do not define a display format, the CockroachDB SQL client will automatically use
ndjsonformat. - If you specify a display format, the client will use that format (e.g.,
--format=csv). - If you set the client display format to
ndjsonand set the changefeed tocsv, you’ll receive JSON format with CSV nested inside. - If you set the client display format to
csvand set the changefeed tojson, you’ll receive a comma-separated list of JSON values.
Show
To show a list of Enterprise changefeed jobs:jobs.retention_time .For more information, refer to .Pause
To pause an Enterprise changefeed:Resume
To resume a paused Enterprise changefeed:Cancel
To cancel an Enterprise changefeed:Modify a changefeed
To modify an Enterprise changefeed, the job and then use: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:paused, which can be verified with .To resume all running changefeeds:running.Known limitations
- Changefeed target options are limited to tables and .
- 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.
- Webhook sinks only support HTTPS. Use the parameter when testing to disable certificate verification; however, this still requires HTTPS and certificates.
- Formats for changefeed messages are not supported by all changefeed sinks. Refer to the page for details on compatible formats with each sink and the option to specify a changefeed message format.
- Using the and options on the same changefeed will cause an error when using the following : Kafka and Google Cloud Pub/Sub. Instead, use the individual
FAMILYkeyword to specify column families when creating a changefeed. - Changefeed types are not fully integrated with . Running changefeeds with user-defined composite types is in . Certain changefeed types do not support user-defined composite types. Refer to the change data capture for more detail. The following limitations apply:
- A changefeed in will not be able to serialize .
- A changefeed emitting will include
ASlabels in the message format when the changefeed serializes a .
- Changefeeds that use the set to a could create a plan that assigns most of the ranges to an on the coordinator node. This leads to an unbalanced plan and slow changefeed progress, particularly when the table is large and has many ranges.
ALTER CHANGEFEEDis not fully supported with changefeeds that use CDC queries. . You can alter the options that a changefeed uses, but you cannot alter the changefeed target tables.- Creating a changefeed with CDC queries on tables with more than one column family is not supported.
- When you create a changefeed on a table with more than one column family , the changefeed will emit messages per column family in separate streams. As a result, for different column families will arrive at the under separate topics.

