Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsApr 11, 2026·2 min de lecture

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.

Introduction

CockroachDB is a distributed SQL database designed for the cloud. Inspired by Google Spanner, it offers serializable transactions, horizontal scale, automatic sharding, and survivability (nodes can fail, zones can fail, regions can fail). PostgreSQL-compatible wire protocol and most PostgreSQL syntax.

What CockroachDB Does

  • Serializable transactions — strongest ACID guarantee
  • PostgreSQL compatibility — wire protocol + most SQL features
  • Auto-sharding — data split into ranges, auto-rebalanced
  • Multi-region — place data near users via zone configs
  • Raft replication — configurable replica count per table
  • Online schema changes — non-blocking DDL
  • Time travel queries — AS OF SYSTEM TIME
  • Follower reads — read from closest replica for low latency
  • CDC — change data capture stream

Architecture

Each node is identical (no primary/secondary). Data is split into 64MB ranges, each replicated via Raft to typically 3 nodes. SQL layer sits on top of the distributed KV layer. DistSQL executes queries across nodes in parallel.

Self-Hosting

# Secure 3-node cluster
cockroach start --certs-dir=certs --listen-addr=node1:26257 \
  --advertise-addr=node1 \
  --join=node1,node2,node3

# Init cluster
cockroach init --certs-dir=certs --host=node1

Key Features

  • Distributed SQL with serializable transactions
  • PostgreSQL wire compatibility
  • Multi-region with geo-partitioning
  • Automatic sharding and rebalancing
  • Zero-downtime upgrades
  • Online schema changes
  • Backup and restore
  • Row-level TTL
  • Change data capture
  • BACKUP to cloud storage

Comparison

Database Inspired By Compatibility License
CockroachDB Spanner PostgreSQL BUSL + CCL
YugabyteDB Spanner PostgreSQL Apache 2.0
TiDB Spanner + HTAP MySQL Apache 2.0
Spanner Own Managed only Proprietary
Citus (Postgres ext) Postgres PostgreSQL Apache 2.0

FAQ

Q: A PostgreSQL drop-in? A: Most PostgreSQL features are compatible. Incompatibilities include: stored procedures (limited support), certain types, and some PG extensions. Test before migrating.

Q: Performance overhead? A: Distributed transactions are slower than single-machine (latency ≈ 2-3 network RTTs). But the horizontal scaling capability far surpasses a single machine. For small apps, single-node Postgres is faster and cheaper.

Q: BUSL restrictions? A: Source is readable and self-usable, but you cannot run a commercial managed service that competes with Cockroach Cloud. Automatically converts to Apache 2.0 after 4 years.

Sources

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires