fix(db): replace lib/pq with pgx for connection pooler compatibility#6209
Open
brandonros wants to merge 1 commit intowoodpecker-ci:mainfrom
Open
fix(db): replace lib/pq with pgx for connection pooler compatibility#6209brandonros wants to merge 1 commit intowoodpecker-ci:mainfrom
brandonros wants to merge 1 commit intowoodpecker-ci:mainfrom
Conversation
lib/pq uses PostgreSQL's extended query protocol with unnamed prepared statements for all parameterized queries, which is incompatible with connection poolers (pgBouncer, pgcat) in transaction pooling mode. Switch to pgx/stdlib which supports simple query protocol via the DSN parameter `default_query_exec_mode=simple_protocol`, avoiding prepared statements entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
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.
Summary
Fixes #6097
Replace
github.com/lib/pqwithgithub.com/jackc/pgx/v5/stdlibas the PostgreSQL driver.lib/pquses PostgreSQL's extended query protocol with unnamed prepared statements for all parameterized queries. This is incompatible with connection poolers (pgBouncer, pgcat) in transaction pooling mode — the pooler can route different clients' Parse/Bind messages to the same server connection, causing:pgxsupports simple query protocol via the DSN parameterdefault_query_exec_mode=simple_protocol, which avoids prepared statements entirely and is fully compatible with transaction pooling.Changes
server/store/datastore/init.go/init_cgo.go— Swaplib/pqimport forpgx/v5/stdlibserver/store/datastore/engine.go— Map"postgres"driver name to"pgx"(pgx/stdlib registers under"pgx")server/store/datastore/migration/migration_test.go— Update imports and driver namesgo.mod/go.sum— Addpgx/v5, remove directlib/pqdependencyWhy pgx
pgx/stdlib(implementsdatabase/sqlinterface — XORM works without changes)default_query_exec_mode=simple_protocolto avoid prepared statementslib/pqis in maintenance mode; its author recommends migrating to pgxImpact
?default_query_exec_mode=simple_protocolto theirWOODPECKER_DATABASE_DATASOURCEto resolve the errorPerformance note
Simple protocol sends parameters as text (not binary) and cannot reuse prepared statement query plans. For Woodpecker's workload (simple CRUD queries), the difference is negligible.
🤖 Generated with Claude Code