Skip to content

fix(common.postgresql): Skip connection liveness ping for PgBouncer#19258

Open
skartikey wants to merge 2 commits into
influxdata:masterfrom
skartikey:pgbouncer_issue_19252
Open

fix(common.postgresql): Skip connection liveness ping for PgBouncer#19258
skartikey wants to merge 2 commits into
influxdata:masterfrom
skartikey:pgbouncer_issue_19252

Conversation

@skartikey

@skartikey skartikey commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Since the pgx v5 bump (#18587, v1.38.2) the driver executes "-- ping" before reusing a connection idle for more than one second. PgBouncer's admin console cannot parse this query, so every gather cycle floods the PgBouncer log with "invalid command" errors and the failed ping forces a reconnect.

Skip the ping for admin console connections via the driver's OptionShouldPing hook. This requires creating the database handle from a connector instead of a registered DSN, which as a side effect no longer leaks a driver-registry entry per plugin initialization.

The skip must not reach anything else, which the shared IsPgBouncer flag could not express: inputs.postgresql and inputs.postgresql_extensible also set it whenever prepared_statements is disabled, i.e. for a real PostgreSQL behind a PgBouncer in transaction mode, which parses "-- ping" fine and needs the liveness check. IsPgBouncer now marks the admin console only, with prepared statements moved to a separate SimpleProtocol flag.

Integration tests cover both sides: the PgBouncer one fails without the fix with the log lines from the issue, the PostgreSQL one asserts the ping survives disabling prepared statements.

Checklist

Related issues

resolves #19252

@telegraf-tiger telegraf-tiger Bot added area/postgresql fix pr to fix corresponding bug labels Jul 13, 2026
@skartikey skartikey self-assigned this Jul 13, 2026
…admin console

The IsPgBouncer flag is also set by the postgresql and postgresql_extensible
plugins whenever prepared_statements is disabled, which is the documented
setting for reaching a server through a PgBouncer with pool_mode set to
transaction. Those connections talk to a real PostgreSQL that parses the
"-- ping" liveness query fine, so skipping the ping there only drops the
liveness check without fixing anything.

Let IsPgBouncer mark the admin console only and move the prepared-statement
handling to a separate SimpleProtocol flag. Cover the PostgreSQL side with an
integration test asserting that disabling prepared statements keeps the ping.
@telegraf-tiger

Copy link
Copy Markdown
Contributor

@srebhan srebhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job @skartikey! Approving it, so feel free to merge it if testing succeeds without any change to the code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/postgresql fix pr to fix corresponding bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inputs.pgbouncer floods with "ERROR invalid command '-- ping'" to pgbouncer.log

2 participants