Skip to main content
New in v23.1: CREATE SCHEDULE FOR CHANGEFEED allows you to create a scheduled changefeed to export data out of CockroachDB. Scheduled changefeeds have the scale, observability, and endpoint sink options that changefeed jobs include, with the convenience of setting a regular schedule. A changefeed job created with CREATE SCHEDULE FOR CHANGEFEED performs a one-time table scan using the functionality to create an export of your table data. For more detail on using changefeeds to create an export of your table data, see .

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_schedule_for_changefeed syntax diagram

Parameters

Changefeed options

You can include the changefeed options listed on the page to modify the behavior of your changefeed. The following options are not compatible with scheduled changefeeds:
  • diff
  • end_time
  • mvcc_timestamp
  • resolved
  • updated
Scheduled changefeeds have the option included implicitly. You cannot specify initial_scan as 'yes' or 'no'.

Schedule options

Examples

Before running any of the examples in this section, it is necessary to enable the kv.rangefeed.enabled cluster setting. If you are working on a CockroachDB Standard or Basic cluster, this cluster setting is enabled by default. The page provides detail on the available sinks for your change data messages and connection URIs. We recommend using to interact with external sinks. The examples in this section use an external connection URI for the changefeed sink.

Create a scheduled changefeed

The following statement sets up a scheduled changefeed named users_rides_nightly that will send changefeed messages in CSV format 1 minute past midnight every night. As soon as the statement is run, the first changefeed run will execute immediately:
The control the schedule’s behavior:
  • If it runs into an error, on_execution_failure=retry will ensure that the schedule retries the changefeed immediately.
  • If the previous scheduled changefeed is still running, on_previous_running=skip will skip a new changefeed at the next scheduled time.
The output will confirm that the changefeed has added the initial_scan = 'only' option implicitly:

Create a scheduled changefeed with CDC queries

You can use CDC queries with scheduled changefeeds to define expression syntax that selects columns and applies filters to further restrict or transform the data in your changefeed messages. When you add this expression syntax to your changefeed statement, you can only target one table. For guidance on syntax and more example use cases, see . This scheduled changefeed filters for the usage of promotion codes in the database and sends the changefeed messages on a daily basis:

View scheduled changefeed details

To all scheduled changefeeds:
To view the details of only running scheduled changefeeds:
To view the details of only paused scheduled changefeeds:
To view the details of a specific scheduled changefeed:
To a scheduled changefeed:
To a scheduled changefeed:
To a scheduled changefeed:
To see the full for the scheduled changefeed:

See also