CockroachDB
DocsDatabasesCockroachDB

CockroachDB

Managed CockroachDB: a distributed SQL database that speaks the PostgreSQL wire protocol, with single-node or multi-node high availability.

Adding CockroachDB from the Databases catalog and attaching it to the app injects COCKROACH_HOST and a Postgres-compatible DATABASE_URL.

Creating a CockroachDB instance

From the phase canvas, click + Service DatabasesCockroachDB, then Commit. Pick a plan and storage size, and StackBlaze provisions the instance for you.

Attach the instance from the add-on Connections list or the app Add-ons tab. Check the app Variables tab for the injected keys after you Commit.

Connecting

CockroachDB speaks the PostgreSQL wire protocol, so any PostgreSQL driver, ORM, or client library works without modification. Point your existing Postgres tooling at the connection string and it just works.

Services in the same project reach the database over the cluster's private network using its internal hostname. The internal connection string takes the form below (note the CockroachDB default port 26257):

Connection string (internal)
postgresql://user:password@[service-name]:26257/dbname?sslmode=verify-full

Browse and query with CloudBeaver

Every database add-on ships with CloudBeaver. Open with DB Beaver on the add-on's Overview starts a scoped session where you can browse tables, run SQL, and edit data in the browser.

Open with DB Beaver launches a scoped CloudBeaver session where the users table is browsed, a query runs, and the results appear.

Standard vs high availability

You choose between Standard and high availability when creating the instance. Standard runs a single node, which is a great fit for development and lower-stakes workloads. High availability runs a multi-node cluster (three or more nodes) where every node serves both reads and writes. If a node is lost, the cluster keeps serving traffic with no manual failover.

StandardHigh availability
TopologySingle nodeMulti-node cluster (3 or more nodes)
Reads and writesServed by the one nodeServed by every node
Survives a node lossNoYes, with no manual failover
Best forDevelopment and testingProduction and resilient workloads

Connecting from Node.js

Because CockroachDB is wire-compatible with PostgreSQL, the standard node-postgres (pg) client connects directly using the injected DATABASE_URL:

db.js
const { Pool } = require('pg')

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
})

async function main() {
  const { rows } = await pool.query('SELECT now()')
  console.log(rows[0])
}

main()

Backups

StackBlaze takes automated, encrypted backups daily. These follow the platform backup policy that applies to all managed databases. For details on schedules, restores, and how the policy works, see /docs/databases/backups.

Under the hood

CockroachDB is a distributed SQL database. StackBlaze runs it via a Kubernetes operator as a StatefulSet with a persistent volume per node. In high availability mode, nodes are spread across the cluster so the database tolerates the loss of any single node.