refactor(data): migrate pgx connector stack from v4 to v5#113
Open
rguichard wants to merge 1 commit into
Open
Conversation
Moves the PostgreSQL connector to github.com/jackc/pgx/v5 (v5.10.0), dropping the v1-era pgconn/pgtype/pgio/pgproto3 dependency stack. Pool creation now goes through connectPostgreSQLPool, which pairs pgxpool.NewWithConfig with an eager Ping: v5 pools always connect lazily, but the initializer retry loop and the ErrConnectorNotReady sentinel depend on pool construction failing fast when the server is unreachable. Without the ping, a reconnect after schema setup would publish a dead pool as ready. pgx.ErrNoRows comparisons switch to errors.Is since v5 can wrap the sentinel. The RDS IAM BeforeConnect hook and the SQLSTATE 08xxx transport-error matching only needed import bumps. Validated against real Postgres containers (startup readiness both ways, all advisory-lock scenarios) plus full make test-fast. Resolves PLA-1392.
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.
Resolves PLA-1392 (follow-up from PLA-1353; audit notes in
docs/plans/2026-05-06-pgx-v5-migration.md).Summary
Migrates the eRPC PostgreSQL connector stack from
github.com/jackc/pgx/v4togithub.com/jackc/pgx/v5(v5.10.0).Changes
go.mod/go.sum:pgx/v4and the directpgconnv1 dependency replaced bypgx/v5; the v1-erapgtype,pgio, andpgproto3/v2indirects drop out,puddle/v2comes in.data/postgresql.go:github.com/jackc/pgx/v5,github.com/jackc/pgx/v5/pgxpool, andgithub.com/jackc/pgx/v5/pgconn(the audit missed thatisPostgresConnectionErrorusespgconn.PgErrordirectly for SQLSTATE 08xxx matching).connectPostgreSQLPoolhelper:pgxpool.NewWithConfig+ eagerPing. pgx v5 pools always connect lazily, but the connector's initializer/retry design (and theErrConnectorNotReadysentinel) depends on pool construction failing fast when the server is unreachable. Without the ping, a reconnect after schema setup would publish a dead pool as ready. Used for the main pool, readonly replicas, and the listener pool.err == pgx.ErrNoRowscomparisons switched toerrors.Issince v5 can wrap the sentinel.data/postgresql_iam_auth.go: import bump only — v5 keeps thefunc(ctx, *pgx.ConnConfig) errorBeforeConnecthook shape, andUser/Passwordare promoted from the embeddedpgconn.Config.data/postgresql_test.go,auth/strategy_database_test.go: import bumps only.docs/plans/2026-05-06-pgx-v5-migration.md: marked implemented with an outcome section.Testing
go test ./data -run 'TestPostgre' -count=1— all pass against real Postgres containers, includingTestPostgreConnectorInitialization(both readiness cases — the invalid-address case exercises the lazy-connect concern directly) and all fiveTestPostgreSQLDistributedLockingadvisory-lock scenarios.go test ./auth—classifyDbError/isDownSignalregression guards pass with v5PgErrorvalues.make test-fast— green.Risks
puddle/v2); the eager-ping helper preserves the v4 startup contract, and the 2026-05-13 incident regression tests (TestIsPostgresConnectionError, coalescing/schema-gate tests) all pass unchanged.Summary
The PostgreSQL connector and its supporting files relied on the v4 generation of the
jackc/pgxlibrary, along with a separategithub.com/jackc/pgconnv1 direct dependency. This change upgrades the entire stack togithub.com/jackc/pgx/v5(v5.10.0) to eliminate the v1-era sub-packages, benefit from v5's API improvements, and shed a large cluster of transitive indirect dependencies.A key behavioral difference required attention: unlike v4's
pgxpool.ConnectConfig, the v5 equivalent (pgxpool.NewWithConfig) connects lazily and never fails at construction time. A newconnectPostgreSQLPoolhelper wrapsNewWithConfigwith an eagerPingto preserve the fail-fast semantics that the initializer retry loop and theErrConnectorNotReadysentinel rely on.Changes
go.mod/go.sum: replacedgithub.com/jackc/pgconn v1andgithub.com/jackc/pgx/v4direct dependencies withgithub.com/jackc/pgx/v5 v5.10.0; dropped v1-era transitives (chunkreader/v2,pgio,pgproto3/v2,pgtype,puddle v1,shopspring/decimal,lib/pq,cockroachdb/apd,gofrs/uuid); addedpuddle/v2 v2.2.2.data/postgresql.go: updated all imports frompgx/v4and standalonepgconntopgx/v5; replaced every call topgxpool.ConnectConfigwith the newconnectPostgreSQLPoolhelper (covers the primary connect task, readonly replica pools, and the listener pool); switched twoerr == pgx.ErrNoRowsequality checks toerrors.Isto handle wrapped sentinels in v5.data/postgresql.go—connectPostgreSQLPool: new function that callspgxpool.NewWithConfigthen immediatelyPings the server, closing the pool and propagating the error on failure. This restores the v4 eager-dial contract required by the initializer's retry and not-ready logic.data/postgresql_iam_auth.go: import bumped frompgx/v4topgx/v5; no logic changes needed (BeforeConnecthook shape and promotedUser/Passwordfields are compatible).data/postgresql_test.goandauth/strategy_database_test.go: imports updated topgx/v5andpgx/v5/pgconn.docs/plans/2026-05-06-pgx-v5-migration.md: status updated to Implemented; implementation outcome section added documenting the corrections to the original audit and final validation results.Testing
BeforeConnecthook with a mockedrdsutilstoken source.