Repository navigation
Added
wpgx.WithDBTimeout(ctx, name, timeout): a database timeout for the statement namedname. It starts once the statement has a connection (immediately inside a transaction) and lasts until the connection is free again (Exec/CopyFrom/Row.Scanreturns, or theRowsare read to the end or closed). Waiting for a pool connection no longer counts against it. Wicked sqlc v2.6.0 generates it for every query'stimeoutoption.- Pool wait bound: a statement with a database timeout waits at most
max(timeout, AcquireTimeout)for a connection.AcquireTimeout(envPOSTGRES_ACQUIRETIMEOUT) defaults to2s, so no new configuration is needed. - Optional
MaxAcquireWaiters(envPOSTGRES_MAXACQUIREWAITERS, default0= no cap): extra waiters fail fast withErrTooManyAcquireWaiters. - Errors
ErrAcquireTimeoutandErrDBTimeouttell the two phases apart; both still matchcontext.DeadlineExceeded.wpgx.StatementErr(ctx, err)marks a deadline error from a statement context withErrDBTimeout. - Metrics:
wpgx_acquire_wait_milliseconds{app,replica},wpgx_db_latency_milliseconds{app,op,replica},wpgx_timeout_total{app,op,replica,phase=acquire|db}, newwpgx_conn_poolops (acquire_waiting,acquire_rejected_count,empty_acquire_count,empty_acquire_wait_seconds,canceled_acquire_count,new_conns_count), and the span attributewpgx.acquire_wait_ms.
Compatibility
- Code that does not call
WithDBTimeout(including code generated by older sqlc) behaves exactly as before. Existing metrics keep their meaning;wpgx_latency_millisecondsstill includes the wait. - The caller's context deadline and cancellation always apply.
Transactis unchanged. - Rows already received before the timeout expires can still be read; the expiry is counted in
wpgx_timeout_total.
Known limitations
- Behind PgBouncer (transaction pooling), time queued inside PgBouncer counts as database time.
- A client-side timeout does not cancel the statement on the server.
Docs: README "Database timeouts"; design record docs/changelogs/2026-11-20-db-timeout-after-acquire.md.
Full Changelog: v0.5.1...v0.6.0