@healthzkit/cockroach package provides a HealthAdapter helper for CockroachDB via pg (node-postgres). CockroachDB speaks the PostgreSQL wire protocol, so the adapter runs a lightweight SQL probe (default SELECT 1) with client.query. Successful checks return ok with metadata.latencyMs plus any fields from an optional metadata hook; failures return fail with the caught error.
Install the adapter package and the pg client:
pg >= 8.
Options
cockroachPgAdapter accepts BaseCockroachOptions:
Pass either
connectionString or client (not both).
Connection string
PassconnectionString. The adapter maintains an internal Pool with max: 1, **connect()**s a client for each check, runs client.query(query), then **release()**s the client in a finally block.
Optional pgOption merges into the internal Pool constructor (everything except connectionString).
Existing client or pool
Passclient as:
- A
Pool: each check callspool.connect(), runs the query on thePoolClient, then releases it. - A
PoolClientor otherClientBase: the query runs on that instance; release is a no-op.
Scheduling
For busy clusters, pair this adapter with aschedule on the check so readiness reads cached results (see Scheduling).