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 initial scan functionality to create an export of your table data.
For more detail on using changefeeds to create an export of your table data, see Export Data with Changefeeds.
Required privileges
As of v25.1, viewing and managing a changefeed job by users with the
CHANGEFEED privilege is deprecated. This functionality of the CHANGEFEED privilege will be removed in a future release.We recommend transitioning users that need to view and manage running changefeed jobs to roles that own the jobs or granting them the VIEWJOB or CONTROLJOB privilege. For more details, refer to View and manage changefeed jobs.Privilege model
The following summarizes the operations users can run depending on whether the assigned privileges are at the job or table level:CHANGEFEED privilege
Viewing and managing changefeed jobs with the
CHANGEFEED privilege is deprecated as of v25.1. Instead, transition users that need to view and manage running changefeed jobs to roles that own the jobs or granting them the VIEWJOB or CONTROLJOB privilege. For more details, refer to View and manage changefeed jobs.CHANGEFEED privilege to allow them to create changefeeds on a specific table:
CHANGEFEED privilege on a set of tables, they can create changefeeds on the target tables even if the user does not have the CONTROLCHANGEFEED role option or the SELECT privilege on the tables.
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 sink.
You can add CHANGEFEED to the user or role’s default privileges with ALTER DEFAULT PRIVILEGES:
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.
View and manage changefeed jobs
Users can view and manage changefeed jobs when one of the following are met:- Job ownership: They own the job, or are a member of a role that owns a job.
- Global privileges: They are assigned
CONTROLJOBorVIEWJOB.
ALTER JOB statement:
Synopsis
Parameters
Changefeed options
You can include the changefeed options listed on theCREATE CHANGEFEED page to modify the behavior of your changefeed. The following options are not compatible with scheduled changefeeds:
diffend_timemvcc_timestampresolvedupdated
initial_scan = 'only' option included implicitly. You cannot specify initial_scan as 'yes' or 'no'. Because initial_scan = 'only' cannot be combined with the diff, end_time, mvcc_timestamp, resolved, or updated options, scheduled changefeeds cannot use them either.
Schedule options
To avoid multiple clusters running the same schedule concurrently, changefeed schedules will pause when restored onto a different cluster or after physical cluster replication has completed.
Examples
Before running any of the examples in this section, it is necessary to enable thekv.rangefeed.enabled cluster setting. If you are working on a CockroachDB Standard or Basic cluster, this cluster setting is enabled by default.
The Changefeed Sinks page provides detail on the available sinks for your change data messages and connection URIs. We recommend using external connections 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 namedusers_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:
- If it runs into an error,
on_execution_failure=retrywill ensure that the schedule retries the changefeed immediately. - If the previous scheduled changefeed is still running,
on_previous_running=skipwill skip a new changefeed at the next scheduled time.
initial_scan = 'only' option implicitly:
Rotate the sink credentials of a scheduled changefeed
A scheduled changefeed stores only the name of its external connection. Each scheduled run creates a new changefeed job that resolves the external connection when the run starts. To rotate the credentials in the sink URI, for example an expiring cloud storage access key, update the external connection instead of the schedule. You do not need to drop and recreate the schedule. This example creates an external connection for an Amazon S3 sink and a nightly scheduled changefeed that uses it:AUTH=implicit with ASSUME_ROLE in the connection URI instead of access keys.
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 Change Data Capture Queries. This scheduled changefeed filters for the usage of promotion codes in themovr database and sends the changefeed messages on a daily basis:
View scheduled changefeed details
To show all scheduled changefeeds:CREATE SCHEDULE statement for the scheduled changefeed:

