Skip to main content

Required settings

  • Database cluster with changefeed enabled
  • Service account

Setup script

Creating a service account

-- If you are on major version 22
CREATE USER artie WITH LOGIN PASSWORD 'your-password' CONTROLCHANGEFEED VIEWCLUSTERSETTING;

-- If you are on major version 23+
CREATE USER artie WITH LOGIN PASSWORD 'your-password' VIEWCLUSTERSETTING;

Granting read-only access

Use the following script to grant read-only access to the service account. Make sure to replace public and your_schema with the appropriate schema name.
GRANT USAGE ON SCHEMA "public", "your_schema" TO artie;
GRANT SELECT ON ALL TABLES IN SCHEMA "public", "your_schema" TO artie;
ALTER DEFAULT PRIVILEGES IN SCHEMA "public", "your_schema" GRANT SELECT ON TABLES TO artie;

Configuring garbage collection

By default, gc.ttlseconds is configured to 4 hours. You can check this value and also configure this by running the following commands. We recommend setting this to be at least 12 hours, less for databases with small amount of data volume.
SHOW ZONE CONFIGURATION FROM DATABASE your_database;

-- Setting GC TTL to 12 hours
ALTER DATABASE your_database CONFIGURE ZONE USING gc.ttlseconds = 43200;

Enabling changefeed

If you are on CockroachDB Basic or Standard, kv.rangefeed.enabled is enabled by default.
Run the following commands to enable changefeed:
SET CLUSTER SETTING kv.rangefeed.enabled = true;
SET CLUSTER SETTING feature.changefeed.enabled = true;