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

# CockroachDB

> Learn how to use Artie to replicate data from CockroachDB.

## Required settings

* Database cluster with changefeed enabled
* Service account

### Setup script

#### Creating a service account

```sql theme={null}
-- 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.

```sql theme={null}
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](https://www.cockroachlabs.com/docs/v25.4/configure-replication-zones#replication-zone-variables:~:text=\(512%20MiB\)-,gc.ttlseconds,-The%20number%20of) 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.

```sql theme={null}
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

<Note>
  If you are on CockroachDB Basic or Standard, `kv.rangefeed.enabled` is enabled by default.
</Note>

Run the following commands to enable changefeed:

```sql theme={null}
SET CLUSTER SETTING kv.rangefeed.enabled = true;
SET CLUSTER SETTING feature.changefeed.enabled = true;
```
