@healthzkit/postgres package provides HealthAdapter helpers for pg (node-postgres) and postgres (Postgres.js). 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 one database client:
pg and postgres are optional peers — install the driver you use.
Package entrypoints
@healthzkit/postgres-pgAdapter,postgresJsAdapter, and their option types (convenient when you use both or want a single import).@healthzkit/postgres/pg-pgAdapteronly.@healthzkit/postgres/postgres-postgresJsAdapteronly.
Shared options
Both factories shareBasePostgresOptions:
pgAdapter (pg)
Peer: pg >= 8.
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.
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.
postgresJsAdapter (postgres)
Peer: postgres >= 3.
Connection string
PassconnectionString. The adapter dynamically imports postgres, then creates a shared sql instance with { max: 1 }.
sql.unsafe(query) (default SELECT 1). Use only trusted query strings (your own literals or constants).
Existing client
Passclient as an existing Sql (or TransactionSql) instance from your app; no internal pool is created.
Scheduling
For busy databases, pair these adapters with aschedule on the check so readiness reads cached results (see Scheduling).