Skills2026年4月11日·1 分钟阅读

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.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
先审查命令
npx -y tokrepo@latest install 90136870-35f6-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

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.

常见问题

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.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产