CockroachDB

Detailed information on the CockroachDB state store component

Create a Dapr component

Create a file called cockroachdb.yaml, paste the following and replace the <CONNECTION STRING> value with your connection string. The connection string for CockroachDB follow the same standard for PostgreSQL connection string. For example, "host=localhost user=root port=26257 connect_timeout=10 database=dapr_test". See the CockroachDB documentation on database connections for information on how to define a connection string.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: state.cockroachdb
  8. version: v1
  9. metadata:
  10. - name: connectionString
  11. value: "<CONNECTION STRING>"

Spec metadata fields

FieldRequiredDetailsExample
connectionStringYThe connection string for CockroachDB“host=localhost user=root port=26257 connect_timeout=10 database=dapr_test”
actorStateStoreNConsider this state store for actors. Defaults to “false”“true”, “false”

Setup CockroachDB

  1. Run an instance of CockroachDB. You can run a local instance of CockroachDB in Docker CE with the following command:

    This example does not describe a production configuration because it sets a single-node cluster, it’s only recommend for local environment.

    1. docker run --name roach1 -p 26257:26257 cockroachdb/cockroach:v21.2.3 start-single-node --insecure
  2. Create a database for state data.

    To create a new database in CockroachDB, run the following SQL command inside container:

    1. docker exec -it roach1 ./cockroach sql --insecure -e 'create database dapr_test'

The easiest way to install CockroachDB on Kubernetes is by using the CockroachDB Operator:

Last modified June 23, 2022: Merge pull request #2550 from ItalyPaleAle/cosmosdb-harcoded-dapr-version (cf03237)