CockroachDB
The Shiny.DocumentDb.CockroachDb package provides a CockroachDB-backed document store. CockroachDB is
PostgreSQL wire-compatible and uses the same Npgsql driver, so
CockroachDbDatabaseProvider extends PostgreSqlDatabaseProvider and inherits
nearly its entire surface — JSONB storage and operators, CRUD, ON CONFLICT batch/upsert, read-merge-write
patch, temporal history, computed (STORED) columns, partial JSON indexes, and full-text search all lower
to identical SQL. Only the PostgreSQL features that depend on extensions or Postgres-only server machinery are
scoped away.
When to Use
Section titled “When to Use”- A CockroachDB cluster (self-hosted or CockroachDB Cloud) as primary storage
- You want a horizontally-scalable, distributed SQL backend with the PostgreSQL provider’s feature set
Installation
Section titled “Installation”dotnet add package Shiny.DocumentDb.CockroachDb-
Direct instantiation
using Shiny.DocumentDb;using Shiny.DocumentDb.CockroachDb;var store = new DocumentStore(new DocumentStoreOptions{DatabaseProvider = new CockroachDbDatabaseProvider("Host=localhost;Port=26257;Username=root;Database=defaultdb;SSL Mode=Disable;")}); -
Dependency injection
services.AddDocumentStore(opts =>{opts.DatabaseProvider = new CockroachDbDatabaseProvider("Host=localhost;Port=26257;Username=root;Database=defaultdb;SSL Mode=Disable;");});
What works
Section titled “What works”Inherited from the PostgreSQL provider and verified against CockroachDB:
- JSONB storage, full LINQ-to-SQL translation, and partial (per-type) JSON indexes.
- CRUD, batch insert, and bulk import — bulk import streams via multi-row
INSERT(see below). - Patch / merge via the read-merge-write path (
SELECT … FOR UPDATE). - Temporal history, computed columns (
GENERATED ALWAYS AS … STORED), multi-tenancy, and optimistic concurrency (MapVersionProperty). - Full-text search —
MapFullTextProperty+FullTextSearchand the composableDocumentFunctions.LuceneMatch/LuceneScore, backed by aSTOREDtsvector column, a GIN index, andts_rank(CockroachDB 23.1+). - Spatial is native — CockroachDB ships PostGIS-compatible
ST_*built-ins and GiST spatial indexes, soMapSpatialProperty, theGeo*methods, andDocumentFunctionsspatial predicates all push down. NoCREATE EXTENSION postgisis needed (or accepted) — the spatial machinery is built into the binary. - Vector / ANN search is native — CockroachDB has a pgvector-compatible
VECTOR(n)type and the same<->/<=>/<#>distance operators built in, soMapVectorProperty+NearestVectors(Cosine / Euclidean / DotProduct, withWherepre-filter) work with no extension. Search runs brute-force — the pgvectorhnsw/ivfflatindex isn’t used (CockroachDB’s ownCREATE VECTOR INDEXis v25.2+ and L2-only, a possible future opt-in).Hammingis unsupported.
What’s scoped away
Section titled “What’s scoped away”These PostgreSQL features are implemented through extensions or Postgres-only server machinery that CockroachDB does not provide, so they report unsupported rather than emitting incompatible SQL:
- Native change feed — CockroachDB has no
LISTEN/NOTIFY(the Postgres change feed is trigger-drivenpg_notify), soSupportsChangeFeedis false. - Native bulk copy — the binary
COPYfast path is disabled;BulkImportuses the multi-rowINSERTpath instead. - Soundex — no
fuzzystrmatchextension.
Transactions
Section titled “Transactions”CockroachDB transactions are SERIALIZABLE by default and may surface retryable (40001) errors under
contention. Wrap contended batch / unit-of-work operations in application-level retry, as CockroachDB
recommends.