Skip to content

feat: preferred connection type pg only#1623

Open
Rattenkrieg wants to merge 1 commit intoeclipse-vertx:masterfrom
Rattenkrieg:preferred-connection-type-pg
Open

feat: preferred connection type pg only#1623
Rattenkrieg wants to merge 1 commit intoeclipse-vertx:masterfrom
Rattenkrieg:preferred-connection-type-pg

Conversation

@Rattenkrieg
Copy link
Contributor

@Rattenkrieg Rattenkrieg commented Feb 23, 2026

  • Add targetServerType support for PostgreSQL multi-host connection pools, matching the semantics of pgjdbc's targetServerType and libpq's target_session_attrs;
  • Revives Preferred server type connection factory #1064 which targeted 4.x; this implementation is redesigned for the 5.x ConnectionFactory architecture;
  • Supports ANY, PRIMARY, SECONDARY, PREFER_PRIMARY, and PREFER_SECONDARY modes;
  • Server type detection uses PG 14+ in_hot_standby GUC_REPORT (zero-cost, during handshake) with SHOW transaction_read_only fallback for older versions;

Differences from #1064

  • Single shared factory instead of one ConnectionFactory per host - 5.x ConnectionFactory.connect() takes options per-call, so a ServerType[] array indexed by server position replaces per-factory state;
  • Stale cache recovery - when all servers are skipped by cache, retries with cache disabled to force re-verification. Preferred server type connection factory #1064 had no cache invalidation, so failovers caused permanent misrouting;
  • Connection leak on detection failure - if detectServerType fails after connect, the connection is explicitly closed before retrying. Preferred server type connection factory #1064 did not handle this path;
  • Close-before-retry - mismatched connections are closed and the close is awaited before opening the next probe, matching pgjdbc behavior and ensuring PG connection slots are freed promptly;

Connection algorithm

The ServerTypeAwarePgConnectionFactory wraps PgConnectionFactory and manages a list of servers with round-robin selection:

  • PRIMARY / SECONDARY (strict): Probes servers in round-robin order, returns the first match, closes mismatched connections. Fails with an error if no server of the desired type is found;
  • PREFER_PRIMARY / PREFER_SECONDARY: Two-pass approach matching pgjdbc - strict pass first;
    (probe-and-close for mismatches), then falls back to connectToAny which accepts any reachable server regardless of type;
  • ANY: Connects to the first reachable server with no type detection;

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.

1 participant