Skip to content

feat(stdlib): add OptionShouldPing to control ResetSession ping behavior#2380

Merged
jackc merged 1 commit into
jackc:masterfrom
ilyam8:feat-stdlib-shouldping
Sep 10, 2025
Merged

feat(stdlib): add OptionShouldPing to control ResetSession ping behavior#2380
jackc merged 1 commit into
jackc:masterfrom
ilyam8:feat-stdlib-shouldping

Conversation

@ilyam8

@ilyam8 ilyam8 commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

Fixes #1738 (comment)


In pgx/v5, the stdlib driver (database/sql integration) pings the server during Conn.ResetSession whenever a connection is reused after being idle for >1s. This matches pgxpool’s default ShouldPing logic, but for some proxies (e.g. PgBouncer admin console) the PostgreSQL -- ping command is not supported and results in noisy log entries such as:

invalid command '-- ping', use SHOW HELP;

Currently, stdlib users cannot disable this ping without setting MaxIdleConns(0) (which forces every query to open a new connection, causing connect/close churn).

This PR introduces an optional OptionShouldPing hook for stdlib, mirroring the existing pgxpool.ShouldPing design:

  • If OptionShouldPing is not provided, default behavior remains unchanged: ping if idle > 1s.
  • If provided, the hook decides whether a ping should be issued before reuse.

@jackc jackc merged commit 82234cb into jackc:master Sep 10, 2025
18 of 28 checks passed
@ilyam8 ilyam8 deleted the feat-stdlib-shouldping branch September 10, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is it possible to disable the Ping that occurs when acquiring a connection in pgxpool?

2 participants