Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

Sources

Connect CockroachDB as a source

Create a read-only service account, enable changefeeds and connect CockroachDB to Artie, so your pipeline replicates the tables you choose.

Prerequisites

  • A CockroachDB cluster with changefeeds enabled. 4. Enable changefeeds has the commands.
  • The cluster’s host and port. The default port is 26257.
  • The name of the database you replicate.
  • A service account username and password. 1. Create a service account has the commands.

Prepare CockroachDB

Run these commands on your CockroachDB cluster. The Prepare CockroachDB step of the pipeline setup shows the same commands.

1. Create a service account

Create the user Artie connects with. On CockroachDB v23 or later, run:

SQL
CREATE USER artie WITH LOGIN PASSWORD 'YOUR_PASSWORD' VIEWCLUSTERSETTING;

On CockroachDB v22, add CONTROLCHANGEFEED:

SQL
CREATE USER artie WITH LOGIN PASSWORD 'YOUR_PASSWORD' CONTROLCHANGEFEED VIEWCLUSTERSETTING;

Replace YOUR_PASSWORD with the user’s password.

2. Grant read-only access

Grant the service account read access to each schema you replicate from:

SQL
GRANT USAGE ON SCHEMA "public", "SCHEMA_NAME" TO artie;
GRANT SELECT ON ALL TABLES IN SCHEMA "public", "SCHEMA_NAME" TO artie;
ALTER DEFAULT PRIVILEGES IN SCHEMA "public", "SCHEMA_NAME" GRANT SELECT ON TABLES TO artie;

Replace public and SCHEMA_NAME with the schemas you replicate from.

3. Configure garbage collection

gc.ttlseconds defaults to 4 hours. We recommend at least 12 hours.

After a pause or outage, Artie restarts the changefeed from the last resolved timestamp it saved. CockroachDB rejects a start time older than this window, so set it longer than your longest expected pause. A shorter window keeps less multiversion concurrency control (MVCC) history on disk.

Check the current value:

SQL
SHOW ZONE CONFIGURATION FROM DATABASE DATABASE_NAME;

Set the window to 12 hours, which is 43,200 seconds:

SQL
ALTER DATABASE DATABASE_NAME CONFIGURE ZONE USING gc.ttlseconds = 43200;

Replace DATABASE_NAME with the database you replicate.

4. Enable changefeeds

Turn on rangefeeds and changefeeds for the cluster:

SQL
SET CLUSTER SETTING kv.rangefeed.enabled = true;
SET CLUSTER SETTING feature.changefeed.enabled = true;

On CockroachDB Basic and Standard, kv.rangefeed.enabled is on by default.

Connect CockroachDB in Artie

These steps cover the source part of the pipeline setup. For the whole flow, see the quickstart.

  1. Choose the source

    On Choose your source, select CockroachDB, then select Continue.

  2. Choose network access

    On How would you like to connect your source?, select SSH tunnel, Allowlist Artie IPs, or PrivateLink.

  3. Prepare the database

    On Prepare CockroachDB, run the commands in Prepare CockroachDB, then select Continue.

  4. Enter the connection settings

    On Connect CockroachDB, fill in the connection settings.

  5. Verify the source

    Select Verify source. The step shows Source verified.

  6. Continue

    Select Continue.

To check the source later, select Verify later.

When you pick a saved CockroachDB connector that other pipelines use, the setup skips the network access and preparation steps and shows them as done. Connect CockroachDB shows the connector’s details in place of its credential fields. Edit the credentials in Settings → Connectors.

Connection settings

Every field is required.

FieldDefaultValue
HostNoneThe IP address or host name of your cluster, for example server.example.com.
Port26257The port CockroachDB listens on, from 1 to 65535.
UserNoneThe service account user, for example artie.
PasswordNoneThe service account password.
Database nameNoneThe database Artie replicates tables from.

Network access

Artie reaches your cluster through an SSH tunnel, an IP allowlist, or PrivateLink. Connection options describes each method.

Read replica for backfills

To keep backfill reads off your primary, turn on Use a read replica for backfill? and enter Replica host and Replica port. Artie backfills from the replica and keeps reading changes from Host. If Replica port is empty, Artie uses Port.

Advanced options

Advanced options on Connect CockroachDB holds two optional settings.

SettingDefaultWhat it does
LabelNoneTells this connector apart when you reuse it.
Message compressionNone (default)GZIP compresses the messages Artie writes to Kafka. See Message compression.

Changefeed behavior

Artie reads changes with one sinkless changefeed that covers every table in the pipeline. The changefeed emits a resolved timestamp every 30 seconds. After a restart, Artie resumes from the last resolved timestamp it saved.

The changefeed carries new changes only (initial_scan = 'no'). Backfills read the tables directly.

Two column behaviors differ from the source table:

  • Artie skips the hidden crdb_internal_*_shard_N columns that CockroachDB adds for hash-sharded indexes.
  • DECIMAL values of NaN, Infinity and -Infinity arrive as NULL.

Next steps

Was this page helpful?