ConfigsApr 11, 2026·2 min read

CockroachDB — Distributed SQL for the Global Cloud

CockroachDB is a cloud-native, distributed SQL database designed for high availability, effortless horizontal scale, and geographic data placement. PostgreSQL-compatible wire protocol with serializable transactions across regions.

TL;DR
CockroachDB provides distributed SQL with PostgreSQL compatibility and multi-region survivability.
§01

What it is

CockroachDB is a distributed SQL database designed for the cloud. Inspired by Google Spanner, it offers serializable transactions, horizontal scale, automatic sharding, and survivability across node, zone, and region failures. It uses the PostgreSQL wire protocol, so most PostgreSQL drivers and ORMs work without modification.

CockroachDB targets teams building globally distributed applications that need strong consistency guarantees without the operational complexity of manual sharding or replication configuration.

§02

How it saves time or tokens

CockroachDB eliminates the operational burden of manual sharding, replication setup, and failover configuration. You start a cluster, create tables with standard SQL, and CockroachDB handles data distribution, replication, and rebalancing automatically. Adding capacity means adding nodes; the cluster rebalances without downtime. The PostgreSQL-compatible interface means no new query language to learn and no application code changes when migrating from PostgreSQL.

§03

How to use

  1. Install and start a single-node cluster for development:
curl https://binaries.cockroachdb.com/cockroach-v24.3.0.darwin-10.9-amd64.tgz | tar -xz
sudo cp cockroach-v24.3.0.darwin-10.9-amd64/cockroach /usr/local/bin
cockroach start-single-node --insecure --listen-addr=localhost:26257 \
  --http-addr=localhost:8080 --store=cockroach-data
  1. Connect with the SQL shell:
cockroach sql --insecure --host=localhost:26257
  1. Create tables using standard PostgreSQL syntax:
CREATE DATABASE myapp;
USE myapp;
CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  email VARCHAR(255) UNIQUE NOT NULL,
  created_at TIMESTAMPTZ DEFAULT now()
);
INSERT INTO users (email) VALUES ('user@example.com');
SELECT * FROM users;
§04

Example

Multi-region configuration for geo-distributed applications:

-- Set up multi-region locality
ALTER DATABASE myapp SET PRIMARY REGION 'us-east';
ALTER DATABASE myapp ADD REGION 'eu-west';
ALTER DATABASE myapp ADD REGION 'ap-south';

-- Pin data to regions for compliance
ALTER TABLE users SET LOCALITY REGIONAL BY ROW;
INSERT INTO users (email, crdb_region)
VALUES ('eu-user@example.com', 'eu-west');
-- This row is stored and served from EU nodes
§05

Related on TokRepo

§06

Common pitfalls

  • Running CockroachDB on a single node in production defeats its purpose. Deploy at least 3 nodes for fault tolerance.
  • Not understanding CockroachDB's licensing: BSL 1.1 for some features means enterprise features require a license after evaluation.
  • Using CockroachDB for workloads with very high single-row update rates. CockroachDB's distributed consensus adds latency to writes that single-node databases do not have.

Frequently Asked Questions

Is CockroachDB compatible with PostgreSQL?+

CockroachDB uses the PostgreSQL wire protocol and supports most PostgreSQL syntax. Most PostgreSQL drivers, ORMs (ActiveRecord, SQLAlchemy, GORM), and tools work without modification. Some PostgreSQL-specific features like extensions are not supported.

How does CockroachDB handle multi-region deployments?+

CockroachDB supports multi-region configurations where you define primary and secondary regions. Data can be pinned to specific regions for compliance, and reads are served from the closest region. Failover between regions is automatic.

What consistency guarantees does CockroachDB provide?+

CockroachDB provides serializable isolation, the strongest SQL isolation level. All transactions see a consistent snapshot of the database, even across distributed nodes and regions.

Is CockroachDB open source?+

CockroachDB core is available under the BSL 1.1 license, which allows free use but restricts offering it as a managed service. Some enterprise features require a commercial license. The CCL (CockroachDB Community License) covers additional features.

How does scaling work in CockroachDB?+

Add nodes to the cluster and CockroachDB automatically rebalances data across all nodes. No manual sharding, no downtime, no configuration changes. The cluster adapts to the new capacity within minutes.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets