[-] fix PgBouncer reconnect by pgxpool ping, closes #1570 - #1576
Open
pashagolub wants to merge 1 commit into
Open
pashagolub wants to merge 1 commit into
pashagolub wants to merge 1 commit into
Conversation
#1570 pgxpool pings any connection idle for more than a second before handing it out, and pgconn.Ping sends `-- ping`. The PgBouncer admin console rejects that with "invalid command", so the pool discards the connection and logs in again on every metric fetch. Disable the pool's liveness ping for PgBouncer sources. Connect() and Ping() still validate the connection with SHOW VERSION.
pgxpool ping, closes #1570
Coverage Report for CI Build 35357768818Coverage decreased (-0.1%) to 87.777%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions8 previously-covered lines in 1 file lost coverage.
Coverage Stats
馃挍 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
pgwatch reconnects to PgBouncer on every metric fetch. PgBouncer logs an error each time:
Cause
pgxpool.Acquirepings any connection that has been idle for more than a second before handing it out (pgxpool/pool.go), andpgconn.Pingsends-- ping. The PgBouncer admin console rejects that statement, so the pool discards the connection and opens a new one. Withpgbouncer_stats: 5this happens on every fetch.This is not a regression. pgxpool has pinged on acquire since pgx v5, and source connections have been pools since #521. #639 fixed the same error message for the connect path only, by replacing pgwatch's own
Conn.Pingcall withSHOW VERSION; the pool-internal ping was never covered, so #625 was closed while half-fixed.Fix
Set
ShouldPingto always return false for PgBouncer sources.Connect()andPing()still validate the connection withSHOW VERSION, so liveness is checked where it matters; a connection that dies while idle now surfaces as an error on the next metric query instead of at acquire time. Telegraf took the same approach in influxdata/telegraf#19258.ShouldPingrequires pgx v5.7.6 or newer; we are on v5.11.0.Verification
Reproduced the bug against
cybertecpostgresql/pgwatch:6.0.0andedoburu/pgbouncer:v1.25.2-p0with the compose file from the issue: a fresh login every 5 seconds, each closing withinvalid command '-- ping'.The fix itself has not yet been run against a live PgBouncer; it is verified by code inspection only. Worth a manual check before merge.
Fixes #1570
AI & Automation Policy
AI/automation tools used (leave blank if none):
Investigated, reproduced and drafted with Claude Code.
Checklist
go build ./internal/sources/passes and gofmt is clean, but the full build and test run could not be done locally:protocis not installed, soapi/pbis not generated andinternal/testutilfails to compile. Leaving the first box for CI and the author.