Skip to main content
The EXPERIMENTAL CHANGEFEED FOR statement is deprecated as of v25.2 and will be removed in a future release. For the same functionality, use the statement to create a sinkless changefeed.
The EXPERIMENTAL CHANGEFEED FOR creates a new sinkless changefeed, which streams row-level changes to the client indefinitely until the underlying connection is closed or the changefeed is canceled. A sinkless changefeed can watch one table or multiple tables in a comma-separated list. For more information, see .
This feature is in and subject to change. To share feedback and/or issues, contact Support.

Required privileges

In v22.2 and above, CockroachDB introduces a new that provides more fine-grained control over a user’s privileges to work with the cluster, including the ability to create and manage changefeeds.There is continued support for the legacy privilege model for changefeeds in v23.1, however it will be removed in a future release of CockroachDB. We recommend implementing the new privilege model that follows in this section for all changefeeds.
To create a changefeed with EXPERIMENTAL CHANGEFEED FOR, a user must have the SELECT privilege on the changefeed’s source tables. You can a user the SELECT privilege to allow them to create sinkless changefeeds on a specific table:

Legacy privilege model

Changefeeds can only be created by superusers, i.e., . The admin role exists by default with root as the member.

Considerations

  • Because sinkless changefeeds return results differently than other SQL statements, they require a dedicated database connection with specific settings around result buffering. In normal operation, CockroachDB improves performance by buffering results server-side before returning them to a client; however, result buffering is automatically turned off for sinkless changefeeds. Also, sinkless changefeeds have different cancellation behavior than other queries: they can only be canceled by closing the underlying connection or issuing a statement on a separate connection. Combined, these attributes of changefeeds mean that applications should explicitly create dedicated connections to consume changefeed data, instead of using a connection pool as most client drivers do by default. This cancellation behavior (i.e., close the underlying connection to cancel the changefeed) also extends to client driver usage; in particular, when a client driver calls Rows.Close() after encountering errors for a stream of rows. The pgwire protocol requires that the rows be consumed before the connection is again usable, but in the case of a sinkless changefeed, the rows are never consumed. It is therefore critical that you close the connection, otherwise the application will be blocked forever on Rows.Close().
  • In most cases, each version of a row will be emitted once. However, some infrequent conditions (e.g., node failures, network partitions) will cause them to be repeated. This gives our changefeeds an at-least-once delivery guarantee. For more information, see .
  • 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.

Synopsis

Parameters

Options

Avro limitations

Creating a changefeed using Avro is available in Core and with the option. Below are clarifications for particular SQL types and values for Avro changefeeds:
  • must have precision specified.
  • (or its aliases BYTEA and BLOB ) are often used to store machine-readable data. When you stream these types through a changefeed with , CockroachDB does not encode or change the data. However, Avro clients can often include escape sequences to present the data in a printable format, which can interfere with deserialization. A potential solution is to hex-encode BYTES values when initially inserting them into CockroachDB. This will ensure that Avro clients can consistently decode the hexadecimal. Note that hex-encoding values at insertion will increase record size.
  • and types are encoded as arrays of 64-bit integers. For efficiency, CockroachDB encodes BIT and VARBIT bitfield types as arrays of 64-bit integers. That is, base-2 (binary format) BIT and VARBIT data types are converted to base 10 and stored in arrays. Encoding in CockroachDB is big-endian, therefore the last value may have many trailing zeroes. For this reason, the first value of each array is the number of bits that are used in the last value of the array. For instance, if the bitfield is 129 bits long, there will be 4 integers in the array. The first integer will be 1; representing the number of bits in the last value, the second integer will be the first 64 bits, the third integer will be bits 65–128, and the last integer will either be 0 or 9223372036854775808 (i.e., the integer with only the first bit set, or 1000000000000000000000000000000000000000000000000000000000000000 when base 2). This example is base-10 encoded into an array as follows:
    For downstream processing, it is necessary to base-2 encode every element in the array (except for the first element). The first number in the array gives you the number of bits to take from the last base-2 number — that is, the most significant bits. So, in the example above this would be 1. Finally, all the base-2 numbers can be appended together, which will result in the original number of bits, 129. In a different example of this process where the bitfield is 136 bits long, the array would be similar to the following when base-10 encoded:
    To then work with this data, you would convert each of the elements in the array to base-2 numbers, besides the first element. For the above array, this would convert to:
    Next, you use the first element in the array to take the number of bits from the last base-2 element, 10111110. Finally, you append each of the base-2 numbers together — in the above array, the second, third, and truncated last element. This results in 136 bits, the original number of bits.
  • A changefeed in will not be able to serialize .

Examples

Create a changefeed

To start a changefeed:
In the terminal where the sinkless changefeed is streaming, the output will appear:
For step-by-step guidance on creating a sinkless changefeed, see the page.

Create a changefeed with Avro

To start a changefeed in Avro format:
In the terminal where the sinkless changefeed is streaming, the output will appear:
For step-by-step guidance on creating a sinkless changefeed with Avro, see the page.

Create a changefeed on a table with column families

To create a changefeed on a table with column families, use the FAMILY keyword for a specific column family:
To create a changefeed on a table and output changes for each column family, use the split_column_families option:
For step-by-step guidance creating a sinkless changefeed on a table with multiple column families, see the page.

See also