ALTER CHANGEFEED statement modifies an existing . You can use ALTER CHANGEFEED to do the following:
- Add new target tables to a changefeed.
- Remove target tables from a changefeed.
- Set new options on a changefeed.
- Remove existing options from a changefeed.
ALTER CHANGEFEED statement against it. For an example of a changefeed modification using ALTER CHANGEFEED, see Modify a changefeed.
Required privileges
To alter a changefeed, the user must have one of the following:CHANGEFEEDprivilege on the table.adminrole.CONTROLCHANGEFEEDrole option +SELECTon the table. ( Deprecated ) TheCONTROLCHANGEFEEDrole option will be removed in a future release. We recommend using the system-level privilege .
Synopsis
Parameters
| Parameter | Description |
|---|---|
job\_ID | Specify the changefeed job\_ID to modify. |
WITH | Use ADD {tables} WITH initial\_scan = 'yes' to perform a scan when adding a target table or multiple target tables. The ALTER CHANGEFEED statement does not perform an initial scan by default, regardless of whether was set with the originalCREATE CHANGEFEED statement. It is also possible to explicitly state ADD {tables} WITH initial\_scan = 'no', although the default makes this unnecessary. See further details in the Options section. |
ADD | Add a new target table to a changefeed. See the example. |
DROP | Drop a target table from a changefeed. It is not possible to drop all target tables from a changefeed. See the example. |
SET | Set new options on a changefeed. ALTER CHANGEFEED ... SET ... uses the options with some exceptions. See the example. |
UNSET | Remove options that were set with the original CREATE CHANGEFEED statement with some exceptions. See the example. |
Options
Consider the following when specifying options withALTER CHANGEFEED:
-
You can set a different for an existing changefeed with the
sinkoption. It is not possible to change the sink type. For example, you can useSET sink = 'gs://{BUCKET NAME}?AUTH=IMPLICIT'to use a different Google Cloud Storage bucket. However, you cannot use thesinkoption to move to Amazon S3 (s3://) or Kafka (kafka://). See the Set options on a changefeed example. -
The majority of options are compatible with
SET/UNSET. This excludes the following options, which you cannot use in anALTER CHANGEFEEDstatement:- : This option will not apply to existing tables. To use the fully qualified table name, it is necessary to create a new changefeed.
-
To use with
ALTER CHANGEFEED, it is necessary to define aWITHclause when runningADD. This will set these options on the specific table(s):Settinginitial_scan = 'yes'will trigger an initial scan on the newly added table. You may also explicitly defineinitial_scan = 'no', though this is already the default behavior. The changefeed does not track the application of this option post scan. This means that you will not see the option listed in output or after aSHOW CHANGEFEED JOBstatement.
Examples
Modify a changefeed
To use theALTER CHANGEFEED statement to modify a changefeed, it is necessary to first pause the running changefeed. The following example demonstrates creating a changefeed, pausing the changefeed, modifying it, and then resuming the changefeed.
For more information on enabling changefeeds, see .
-
Create the changefeed. This example changefeed will emit change messages to a cloud storage sink on two watched tables. The emitted messages will include the , , and options:
-
Use with the job_ID to view the details of a changefeed:
To output a list of all changefeeds on the cluster, run the following:
-
In preparation for modifying the created changefeed, use :
-
With the changefeed paused, run the
ALTER CHANGEFEEDstatement withADD,DROP,SET, orUNSETto change the target tables or options:The output fromALTER CHANGEFEEDwill show theCREATE CHANGEFEEDstatement with the options you’ve defined. After modifying a changefeed withALTER CHANGEFEED, theCREATEdescription will show the fully qualified table name. For an explanation on each of these options, see theCREATE CHANGEFEED. -
Resume the changefeed job with
RESUME JOB:
Add targets to a changefeed
The following statement adds thevehicles and rides tables as new table targets to the changefeed:
Drop targets from a changefeed
The following statement removes therides table from the changefeed’s table targets:
Set options on a changefeed
UseSET to add a new option(s) to a changefeed:
ALTER CHANGEFEED... SET can implement the options with some exceptions.
Use the sink option to change the sink URI to which the changefeed emits messages:
kafka://, for example, then you can only change to a different Kafka URI. Similarly, for cloud storage sinks, the cloud storage scheme must remain the same (e.g., s3://), but you can change to a different storage sink on the same cloud provider.
To change the , create a new changefeed.
Unset options on a changefeed
To remove options from a changefeed, useUNSET:
Modify a changefeed targeting tables with column families
To add a table with when modifying a changefeed, perform one of the following:-
Use the
FAMILYkeyword to define specific families: -
Or, set the option:
DROP it in the same way that you added it originally as a changefeed target. For example:
-
If you used
FAMILYto add the table to the changefeed, useFAMILYwhen removing it:When using theFAMILYkeyword, it is possible to remove only one family at a time as needed. You will receive an error if you try to remove a table without specifying theFAMILYkeyword. -
Or, if you originally added the whole table and its column families with
split_column_families, then remove it without using theFAMILYkeyword:
FAMILY keyword and split_column_families, see .
Known limitations
- It is necessary to the changefeed before performing any statement.
-
CockroachDB does not keep track of the option applied to tables when it is set to
yesoronly. For example:This will trigger an initial scan of the table and the changefeed will tracktable. The changefeed will not trackinitial_scanspecified as an option, so it will not display in the output or after aSHOW CHANGEFEED JOBstatement. -
ALTER CHANGEFEEDis not fully supported with changefeeds that use . You can alter the options that a changefeed uses, but you cannot alter the changefeed target tables.

