Skip to content

sql-pg: PgClient.make keeps its session pool private, so apps can't export pool occupancy metrics #9086

Closed

Description

@aniravi24

Capability request

Could the native PostgreSQL client expose a supported snapshot of connection-pool occupancy: idle sessions, used sessions, callers waiting for a session, and the configured maximum?

This is an API/observability request, not a driver correctness bug.

Public API observations

On main at 1bfd8fd:

  • PgClient.make constructs a PgPool and returns the client without exposing that pool or a statistics snapshot (PgClient.ts L177-L185).
  • PgPool exposes acquisition operations but no occupancy API (PgPool.ts L75-L107). Its underlying effect/Pool is local to the implementation (L145-L172).
  • Older fromPool accepted a caller-provided pg.Pool, whose counters were publicly observable. #7426 replaced that adapter with the native driver. This request is not to restore the old adapter.

Related: #8676 adds statement wait/connect tracing. An occupancy snapshot or gauges would complement that, rather than duplicate it.

Possible API

For example, a proposed client-level API (not one that exists today):

interface PgClient {
  readonly poolStats: Effect.Effect<{
    readonly idle: number
    readonly used: number
    readonly pending: number
    readonly max: number
  }>
}

Built-in gauges would also cover the capability. Raw access to the underlying pool is not necessary and could bypass the driver's TTL/dead-session handling.

With multiplexing, used sessions and in-flight statements are different counts. A statistics snapshot should define which it reports and should not imply a synchronization guarantee.

Environment

  • Effect 4.0.3 and @effect/sql-pg 4.0.3.
  • Public API checked at 1bfd8fddebc978643b7a2077a837b82dc8998177.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions