CockroachDB vs PostgreSQL: Distributed SQL or the Real Thing?
CockroachDB vs PostgreSQL comes down to one question: do you need a single logical database spread across many machines or regions? If you do, CockroachDB is built for exactly that, and PostgreSQL needs extra tooling to get close. If you do not, PostgreSQL is the better default. It is faster on a single node, fully compatible with its own ecosystem, and free under a permissive open source licence.
CockroachDB speaks the PostgreSQL wire protocol, so psql and PostgreSQL drivers connect to it. That makes the two look more interchangeable than they are. It is a different database with its own storage engine, transaction model, and gaps in compatibility.
To check the differences, I ran PostgreSQL 18.6 (postgres:18) and CockroachDB v26.3.2 (cockroachdb/cockroach:latest) side by side in Docker. The outputs below come from those runs.
| PostgreSQL | CockroachDB | |
|---|---|---|
| Architecture | Single primary, optional read replicas | Many nodes, data split into replicated ranges |
| Write scaling | Vertical, or sharding with extensions or application logic | Horizontal: add nodes |
| Default isolation | Read committed | Serializable |
| Failure handling | Failover to a replica, managed by external tooling or your provider | Survives node loss automatically through consensus replication |
| Multi-region | Replicas in other regions, one write region | Built-in regional tables and survival goals |
| PostgreSQL compatibility | Complete | Wire protocol and most SQL, with gaps |
| Extensions | Hundreds | A small built-in set; no custom extensions |
| Licence | PostgreSQL License (open source) | CockroachDB Software License (source available) |
| Self-hosted cost | Free | Free under $10M annual revenue, paid above |
If you are weighing Neon against CockroachDB specifically, read Neon vs CockroachDB, which covers serverless Postgres against distributed SQL. This post compares the engines themselves.
Architecture: one primary vs many equal nodes
PostgreSQL runs on one server that accepts writes. You can add streaming replicas for reads and failover, but every write goes to the primary, and a failover promotes a replica using tools such as Patroni or your cloud provider's automation.
CockroachDB splits every table into ranges, which default to a maximum of 512 MiB, and replicates each range across nodes using the Raft consensus protocol. Any node can accept a query and route it to the right ranges. When a node fails, the remaining replicas keep serving, and the cluster re-replicates the missing copies without anyone promoting anything.
That design is what you pay for with CockroachDB. It is also where the costs come from: every write needs agreement from a majority of a range's replicas, which adds network round trips. On a single machine, PostgreSQL has none of that overhead.
PostgreSQL compatibility is good but partial
CockroachDB advertises itself as a PostgreSQL server version. On v26.3.2:
Most everyday SQL works unchanged: tables, joins, CTEs, window functions, JSONB, SELECT ... FOR UPDATE, user-defined functions, and triggers. The differences show up in the details, and they are the kind a test suite catches late.
SERIAL does not mean a sequence
By default, CockroachDB turns SERIAL into DEFAULT unique_rowid(), which produces large, non-contiguous 64-bit values. Code that expects ids starting at 1, or that passes ids to JavaScript as numbers, breaks. Setting serial_normalization = 'sql_sequence' restores a real sequence, but the notice explains why CockroachDB avoids that: sequential keys send every insert to the same range, creating a hotspot. The recommended key is a UUID with DEFAULT gen_random_uuid().
A table without a primary key gets a hidden one:
Integer division returns a decimal
PostgreSQL returns 3 for 7 / 2. CockroachDB returns 3.5 and uses // for floor division. Any query that relies on integer division, such as bucketing or pagination arithmetic, returns different numbers without raising an error.
Missing features
These all work in PostgreSQL 18 and failed on CockroachDB v26.3.2:
Range types, session-level advisory locks, and LISTEN/NOTIFY are all absent. Transaction-scoped advisory locks such as pg_advisory_xact_lock are supported. The official compatibility page keeps the current list, including XML functions, foreign data wrappers, and column-level privileges.
Extensions
PostgreSQL's extension ecosystem is one of its biggest advantages, and CockroachDB cannot load extensions. Some familiar statements succeed anyway:
All three return CREATE EXTENSION, but pg_extension stays empty. CockroachDB implements a VECTOR type, spatial functions, and trigram indexes natively and accepts these statements so that migrations written for PostgreSQL still run. The underlying implementations are CockroachDB's, not the extensions, so check each function you use. For comparison, the real pgvector extension is covered in our pgvector guide.
Anything outside that built-in set, like TimescaleDB, Citus, pg_cron, or pg_partman, has no CockroachDB equivalent to install.
Transactions: serializable by default
The transaction model affects application code more than any other difference. PostgreSQL defaults to READ COMMITTED. CockroachDB defaults to SERIALIZABLE:
The classic demonstration is write skew. Two doctors are on call, and a rule says at least one must stay on call. Two transactions each check the count, see 2, and take a different doctor off call:
On PostgreSQL 18 with default settings, both commit and the rule is broken:
On CockroachDB, session B commits and session A fails at COMMIT:
The data stays correct, with doctor 1 still on call. The cost is that your application must catch this error (SQLSTATE 40001) and retry the transaction. Under contention, retries are routine on CockroachDB, not an edge case.
PostgreSQL can give you the same guarantee when you ask for it. The same test with BEGIN ISOLATION LEVEL SERIALIZABLE fails one transaction:
CockroachDB also supports READ COMMITTED. On v26.3.2 the sql.txn.read_committed_isolation.enabled cluster setting is on, and BEGIN ISOLATION LEVEL READ COMMITTED gives a read committed transaction. That helps when porting PostgreSQL code that was never written to retry.
Work With Your Databases Like A Pro
Query, explore, and manage your databases with a beautiful desktop app and built-in AI.
Download Now
Scaling and multi-region
PostgreSQL scales reads well with replicas and scales writes vertically. A large modern server takes PostgreSQL further than most applications will ever need. Beyond that, you shard: with Citus, with application-level routing, or by splitting the product into several databases. Each option works, and each adds engineering you own.
CockroachDB scales writes by adding nodes. Ranges split as they grow and rebalance across the cluster, and the application keeps one connection string and one schema.
Multi-region is where the gap is widest. CockroachDB lets you declare regions on a database, pin rows to a home region with REGIONAL BY ROW tables, and choose whether the database should survive the loss of a zone or of a region. PostgreSQL has no built-in equivalent. You can place read replicas in other regions, but writes still travel to one primary, and surviving a region outage means failing over to another region.
If your requirement is "users in Europe and the US both need low-latency writes, and the database must stay up if a cloud region goes down", that is CockroachDB's home ground. If your requirement is "the app should be fast and not lose data", PostgreSQL with a replica does that.
Performance
I have not published a benchmark here, because a single-node Docker test would measure the wrong thing. CockroachDB's consensus writes are designed for clusters, and its trade-offs only show up across nodes and network links.
The general shape is well established. For a workload that fits on one server, PostgreSQL has lower latency per query because, with default asynchronous replication, a write does not wait for other nodes to agree. CockroachDB's advantage is aggregate throughput as you add nodes, plus availability during failures. Test with your own schema, transaction mix, and cluster layout before trusting any published number, including the vendors'.
Licensing: what changed in 2024
PostgreSQL is released under the PostgreSQL License, a permissive open source licence similar to MIT or BSD. You can run it anywhere, modify it, and sell services on it without paying anyone.
CockroachDB's licensing has changed several times. The current model, set out in the official licensing FAQ, applies to all releases from v24.3.0, which shipped in November 2024:
- The free Core edition was retired. Self-hosted CockroachDB is now offered only as CockroachDB Enterprise, under the CockroachDB Software License. The source is available, but it is not an open source licence.
- Enterprise Free has the same features as paid Enterprise and is free for businesses under $10M in annual revenue, counting the parent company and affiliates. It comes with community support only and must be renewed annually.
- Businesses above that threshold need a paid Enterprise licence.
- Enterprise Free and Enterprise Trial clusters must send telemetry to Cockroach Labs. A cluster that stops sending it for 7 days is throttled to 5 concurrent SQL transactions.
- A cluster with no licence key at all is throttled 7 days after initialisation.
- Single-node clusters for development need no licence key and are not throttled.
That last point is why my test container ran with no key. For a production cluster, the licence is an ongoing obligation to track: revenue eligibility, annual renewal, and telemetry reaching Cockroach Labs from your network.
The CockroachDB Cloud services include an Enterprise licence automatically.
Managed options and pricing models
Both databases are available as managed services.
PostgreSQL is offered by every major cloud (Amazon RDS and Aurora, Google Cloud SQL and AlloyDB, Azure Database for PostgreSQL) and by specialist providers such as Neon and Supabase. Pricing models range from provisioned instances billed by the hour to serverless compute billed by usage. Because the engine is the same everywhere, you can move between providers with pg_dump and a connection string change. For the AWS options, see Aurora vs RDS.
CockroachDB is sold by Cockroach Labs. Since September 2026, new organisations sign up to Cockroach Continuum, which has a Standard edition on shared infrastructure (AWS and Google Cloud) and a Mission Critical edition on dedicated infrastructure (AWS, Google Cloud, and Azure). Both are metered by usage, with on-demand or committed-spend contracts. Existing CockroachDB Cloud customers stay on their current plans unless they opt in. Check the pricing page for current rates, because the plan structure has changed more than once.
The practical difference is vendor choice. A PostgreSQL workload can move to another host whenever pricing or service changes. A CockroachDB workload runs on Cockroach Labs' cloud or on your own infrastructure under their licence.
When to choose PostgreSQL
- Your data fits on one primary server, now and for the foreseeable future. This covers the large majority of applications.
- You rely on extensions such as PostGIS, TimescaleDB, pg_cron, or the real pgvector.
- You use
LISTEN/NOTIFY, range types, session advisory locks, or other features CockroachDB lacks. - You want an open source licence with no revenue threshold or telemetry requirement.
- You want the widest choice of hosting providers and tools.
- Latency per query matters more than surviving a region outage.
PostgreSQL also pairs well with the rest of the relational world. If you are still choosing between relational engines, PostgreSQL vs MySQL covers the other common option.
When to choose CockroachDB
- You need writes to scale beyond what one server can handle, and you do not want to shard the application yourself.
- You need the database to survive a zone or region failure without a manual failover.
- You have users in several regions who need low-latency reads and writes, or data residency rules that pin rows to a region.
- Your team is ready to handle transaction retries and test for the compatibility differences above.
- The licence terms fit: either you qualify for Enterprise Free and accept the telemetry requirement, or the paid licence or managed cloud is in budget.
Migrating between them
Moving from PostgreSQL to CockroachDB is a port, not a restore. Plan for these, all of which came up in the tests above:
- Replace sequential
SERIALkeys withUUIDkeys, or acceptunique_rowid()values in application code. - Search for integer division and change it to
//where you need floor division. - Replace
LISTEN/NOTIFY, session advisory locks, and range types. - Add retry handling for SQLSTATE
40001around every transaction, or opt specific transactions intoREAD COMMITTED. - Remove or replace extensions that CockroachDB does not implement.
Moving from CockroachDB back to PostgreSQL has its own list: CockroachDB-only syntax such as //, STRING columns, unique_rowid() defaults, and the multi-region table settings all need rewriting.
Verdict
Choose PostgreSQL unless you have a concrete requirement for distributed writes, automatic regional failover, or multi-region data placement. It is faster per query on one server, compatible with every PostgreSQL tool and extension, cheaper to run, and free of licence conditions.
Choose CockroachDB when one of those requirements is real and measured, not anticipated. For that problem, it offers something PostgreSQL does not provide out of the box: one SQL database that keeps serving through a failure of a region. Budget for the port, the retry logic, and the licence, and test your actual transaction patterns on a multi-node cluster before you commit.
Whichever you pick, you will want a good client to look at the data. DB Pro is a desktop client for PostgreSQL on macOS, Windows, and Linux.
Keep Reading
PostgreSQL vs SQL Server: Which Should You Choose?
PostgreSQL vs SQL Server compared with real output from PostgreSQL 18 and SQL Server 2025: licensing, locking, collations, T-SQL vs PL/pgSQL, upserts, JSON and vectors, high availability, and migration.
Best Postgres GUI Clients in 2026: 7 Options Compared
The best Postgres GUI depends on how you work. We compare DB Pro, pgAdmin, DBeaver, DataGrip, TablePlus, Postico, and Navicat on platforms, features, and licensing.
PostgreSQL vs MySQL: Real Differences, Tested Side by Side
PostgreSQL vs MySQL compared with real output from PostgreSQL 18 and MySQL 8.4: schema changes, type strictness, collations, upserts, JSON, concurrency, licensing, and when to choose each.