> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ALTER CHANGEFEED

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `ALTER CHANGEFEED` statement modifies an existing <InternalLink path="change-data-capture-overview">changefeed</InternalLink>. 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.

The statement will return a job ID and the new job description.

It is necessary to <InternalLink path="pause-job">**pause**</InternalLink> a changefeed before running the `ALTER CHANGEFEED` statement against it. For an example of a changefeed modification using `ALTER CHANGEFEED`, see [Modify a changefeed](#modify-a-changefeed).

## Required privileges

To alter a changefeed, the user must have one of the following:

* `CHANGEFEED` privilege on the table.
* `admin` role.
* `CONTROLCHANGEFEED` role option + `SELECT` on the table. ( **Deprecated** ) The `CONTROLCHANGEFEED` role option will be removed in a future release. We recommend using the system-level privilege <InternalLink path="security-reference/authorization#supported-privileges">`CHANGEFEED`</InternalLink>.

For more details on the required privileges for changefeeds generally, refer to the <InternalLink path="create-changefeed">`CREATE CHANGEFEED`</InternalLink> page.

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/_CYD-gPJn4sApGw_/images/sql-diagrams/v25.2/alter_changefeed.svg?fit=max&auto=format&n=_CYD-gPJn4sApGw_&q=85&s=20d43f43e00f255c9dab41bcf7aa6537" alt="alter_changefeed syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="591" height="459" data-path="images/sql-diagrams/v25.2/alter_changefeed.svg" />

<img src="https://mintcdn.com/cockroachlabs/40ELkDCuTkDz04_S/images/generated/docs/v25.2/alter-changefeed/syntax-diagram-119b5dcdd46d.svg?fit=max&auto=format&n=40ELkDCuTkDz04_S&q=85&s=8c7c5fd22386e20c7383d0e9c2f1f9c0" alt="SQL syntax diagram" width="591" height="459" data-path="images/generated/docs/v25.2/alter-changefeed/syntax-diagram-119b5dcdd46d.svg" />

## 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 <InternalLink path="create-changefeed">`initial\_scan = 'yes'`</InternalLink> was set with the **original**`CREATE 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](#scan-details) section. |
| `ADD`     | Add a new target table to a changefeed. See the [example](#add-targets-to-a-changefeed).                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `DROP`    | Drop a target table from a changefeed. It is **not** possible to drop all target tables from a changefeed. See the [example](#drop-targets-from-a-changefeed).                                                                                                                                                                                                                                                                                                                                                                                                  |
| `SET`     | Set new options on a changefeed. `ALTER CHANGEFEED ... SET ...` uses the <InternalLink path="create-changefeed#options">`CREATE CHANGEFEED`</InternalLink> options with some [exceptions](#option-exceptions). See the [example](#set-options-on-a-changefeed).                                                                                                                                                                                                                                                                                                 |
| `UNSET`   | Remove options that were set with the original `CREATE CHANGEFEED` statement with some [exceptions](#option-exceptions). See the [example](#unset-options-on-a-changefeed).                                                                                                                                                                                                                                                                                                                                                                                     |

When the listed parameters are used together in the same statement, all changes will apply at the same time with no particular order of operations.

### Options

Consider the following when specifying options with `ALTER CHANGEFEED`:

* You can set a different <InternalLink path="changefeed-sinks#sink-uri">sink URI</InternalLink> for an existing changefeed with the `sink` option. It is **not** possible to change the sink type. For example, you can use `SET sink = 'gs://{BUCKET NAME}?AUTH=IMPLICIT'` to use a different Google Cloud Storage bucket. However, you cannot use the `sink` option to move to Amazon S3 (`s3://`) or Kafka (`kafka://`). See the [Set options on a changefeed](#set-options-on-a-changefeed) example.
* The majority of <InternalLink path="create-changefeed#options">`CREATE CHANGEFEED`</InternalLink> options are compatible with `SET`/`UNSET`. This excludes the following options, which you **cannot** use in an `ALTER CHANGEFEED` statement:
  * <InternalLink path="create-changefeed">`cursor`</InternalLink>
  * <InternalLink path="create-changefeed">`end_time`</InternalLink>
  * <InternalLink path="create-changefeed">`full_table_name`</InternalLink>: This option will not apply to existing tables. To use the fully qualified table name, it is necessary to create a new changefeed.
  * <InternalLink path="create-changefeed">`initial_scan = 'only'`</InternalLink>
* To use <InternalLink path="create-changefeed">`initial_scan`</InternalLink> with `ALTER CHANGEFEED`, it is necessary to define a `WITH` clause when running `ADD`. This will set these options on the specific table(s):

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job ID} ADD movr.rides, movr.vehicles WITH initial_scan = 'yes' SET updated UNSET resolved;
  ```

  Setting `initial_scan = 'yes'` will trigger an initial scan on the newly added table. You may also explicitly define `initial_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 a `SHOW CHANGEFEED JOB` statement.

## Examples

### Modify a changefeed

To use the `ALTER 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.

<Note>
  For more information on enabling changefeeds, see <InternalLink path="create-and-configure-changefeeds">Create and Configure Changefeeds</InternalLink>.
</Note>

1. 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 <InternalLink path="create-changefeed">`resolved`</InternalLink>, <InternalLink path="create-changefeed">`updated`</InternalLink>, and <InternalLink path="create-changefeed">`schema_change_policy`</InternalLink> options:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   CREATE CHANGEFEED FOR TABLE movr.users, movr.vehicles INTO 's3://{BUCKET_NAME}?AWS_ACCESS_KEY_ID={ACCESS_KEY_ID}&AWS_SECRET_ACCESS_KEY={SECRET_ACCESS_KEY}'
       WITH resolved, updated, schema_change_policy = backfill;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
          job_id
   ----------------------
   745448689649516545
   (1 row)
   ```
2. Use <InternalLink path="show-jobs#show-changefeed-jobs">`SHOW CHANGEFEED JOB`</InternalLink> with the job\_ID to view the details of a changefeed:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   SHOW CHANGEFEED JOB 745448689649516545;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   job_id             |                                                                                                          description                                                                                       | user_name | status  |              running_status              |          created          |          started           | finished |          modified          |      high_water_timestamp      | error |                                                sink_uri                                                |             full_table_names             | topics | format
   -------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------+------------------------------------------+---------------------------+----------------------------+----------+----------------------------+--------------------------------+-------+--------------------------------------------------------------------------------------------------------+------------------------------------------+--------+---------
   745448689649516545 | CREATE CHANGEFEED FOR TABLE movr.users, movr.vehicles INTO 's3://{BUCKET_NAME}?AWS_ACCESS_KEY_ID={ACCESS_KEY_ID}&AWS_SECRET_ACCESS_KEY=redacted' WITH resolved, schema_change_policy = 'backfill', updated | root      | running | running: resolved=1647563286.239010012,0 | 2022-03-18 00:28:06.24559 | 2022-03-18 00:28:06.276709 | NULL     | 2022-03-18 00:28:37.250323 | 1647563313622679573.0000000000 |       | s3://{BUCKET_NAME}?AWS_ACCESS_KEY_ID={ACCESS_KEY_ID}&AWS_SECRET_ACCESS_KEY=redacted                    | {movr.public.vehicles,movr.public.users} | NULL   | json
   (1 row)
   ```

   To output a list of all changefeeds on the cluster, run the following:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   SHOW CHANGEFEED JOBS;
   ```
3. In preparation for modifying the created changefeed, use <InternalLink path="pause-job">`PAUSE JOB`</InternalLink>:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   PAUSE JOB 745448689649516545;
   ```
4. With the changefeed paused, run the `ALTER CHANGEFEED` statement with `ADD`, `DROP`, `SET`, or `UNSET` to change the target tables or options:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   ALTER CHANGEFEED 745448689649516545 DROP movr.vehicles UNSET resolved SET diff;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   job_id             |                                                                     job_description
   -------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   745448689649516545 | CREATE CHANGEFEED FOR TABLE movr.public.users INTO 's3://{BUCKET_NAME}?AWS_ACCESS_KEY_ID={ACCESS_KEY_ID}&AWS_SECRET_ACCESS_KEY=redacted' WITH diff, schema_change_policy = 'backfill', updated
   (1 row)
   ```

   The output from `ALTER CHANGEFEED` will show the `CREATE CHANGEFEED` statement with the options you've defined. After modifying a changefeed with `ALTER CHANGEFEED`, the `CREATE` description will show the fully qualified table name.

   For an explanation on each of these options, see the `CREATE CHANGEFEED` <InternalLink path="create-changefeed#options">options</InternalLink>.
5. Resume the changefeed job with `RESUME JOB`:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   RESUME JOB 745448689649516545;
   ```

### Add targets to a changefeed

The following statement adds the `vehicles` and `rides` tables as new table targets to the changefeed:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
 ALTER CHANGEFEED {job_ID} ADD movr.rides, movr.vehicles;
```

To add a table that has <InternalLink path="column-families">column families</InternalLink>, see the [example](#modify-a-changefeed-targeting-tables-with-column-families).

### Drop targets from a changefeed

The following statement removes the `rides` table from the changefeed's table targets:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
 ALTER CHANGEFEED {job_ID} DROP movr.rides;
```

### Set options on a changefeed

Use `SET` to add a new option(s) to a changefeed:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER CHANGEFEED {job_ID} SET resolved='10s', envelope=key_only;
```

`ALTER CHANGEFEED... SET` can implement the <InternalLink path="create-changefeed#options">`CREATE CHANGEFEED`</InternalLink> options with some [exceptions](#options).

<a id="sink-example" /> Use the `sink` option to change the sink URI to which the changefeed emits messages:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER CHANGEFEED {job_ID}
    SET sink = 's3://{BUCKET NAME}?AWS_ACCESS_KEY_ID={ACCESS_KEY_ID}&AWS_SECRET_ACCESS_KEY={SECRET_ACCESS_KEY}'
    UNSET resolved;
```

The type (or scheme) of the sink **cannot** change. That is, if the changefeed was originally sending messages to `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 <InternalLink path="changefeed-sinks">sink type</InternalLink>, create a new changefeed.

### Unset options on a changefeed

To remove options from a changefeed, use `UNSET`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER CHANGEFEED {job_ID} UNSET resolved, diff;
```

### Modify a changefeed targeting tables with column families

To add a table with <InternalLink path="column-families">column families</InternalLink> when modifying a changefeed, perform one of the following:

* Use the `FAMILY` keyword to define specific families:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job_ID} ADD database.table FAMILY f1, database.table FAMILY f2;
  ```
* Or, set the <InternalLink path="create-changefeed">`split_column_families`</InternalLink> option:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job_ID} ADD database.table SET split_column_families;
  ```

To remove a table with column families as a target from the changefeed, you must `DROP` it in the same way that you added it originally as a changefeed target. For example:

* If you used `FAMILY` to add the table to the changefeed, use `FAMILY` when removing it:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job_ID} DROP database.table FAMILY f1, database.table FAMILY f2;
  ```

  When using the `FAMILY` keyword, 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 the `FAMILY` keyword.
* Or, if you originally added the whole table and its column families with `split_column_families`, then remove it without using the `FAMILY` keyword:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job_ID} DROP database.table;
  ```

For further discussion on using the `FAMILY` keyword and `split_column_families`, see <InternalLink path="changefeeds-on-tables-with-column-families">Tables with column families in changefeeds</InternalLink>.

## Known limitations

* It is necessary to <InternalLink path="pause-job">`PAUSE`</InternalLink> the changefeed before performing any <InternalLink path="alter-changefeed">`ALTER CHANGEFEED`</InternalLink> statement.
* CockroachDB does not keep track of the <InternalLink path="create-changefeed">`initial_scan`</InternalLink> option applied to tables when it is set to `yes` or `only`. For example:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job_ID} ADD table WITH initial_scan = 'yes';
  ```

  This will trigger an initial scan of the table and the changefeed will track `table`. The changefeed will **not** track `initial_scan` specified as an option, so it will not display in the output or after a `SHOW CHANGEFEED JOB` statement.
* `ALTER CHANGEFEED` is not fully supported with changefeeds that use <InternalLink path="cdc-queries">CDC queries</InternalLink>. You can alter the options that a changefeed uses, but you cannot alter the changefeed target tables.

## See also

* <InternalLink path="change-data-capture-overview">Change Data Capture Overview</InternalLink>
* <InternalLink path="create-changefeed">`CREATE CHANGEFEED`</InternalLink>
* <InternalLink path="create-and-configure-changefeeds">Create and Configure Changefeeds</InternalLink>
* <InternalLink path="changefeed-sinks">Changefeed Sinks</InternalLink>
* <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>
