Skip to content

Support multiple hosts for PostgreSQL and MySQL - #457

Open
pivotal-david-osullivan wants to merge 3 commits into
mainfrom
postgres-multi-host
Open

Support multiple hosts for PostgreSQL and MySQL#457
pivotal-david-osullivan wants to merge 3 commits into
mainfrom
postgres-multi-host

Conversation

@pivotal-david-osullivan

@pivotal-david-osullivan pivotal-david-osullivan commented Aug 12, 2026

Copy link
Copy Markdown
Member

Addresses #128

java.net.URI cannot parse a multi-host authority such as
jdbc:postgresql://host1:port1,host2:port2/database — it falls back to
registry-based parsing, where getHost() returns null and getPort()
returns -1, even though getAuthority() still holds the full value.

Changes

  • UriInfo now detects that fallback and, when the authority contains a
    comma, parses the host list manually. getHost()/getPort() keep
    returning the first host for backwards compatibility, and a new
    getHostAndPort() accessor exposes the full list.
  • Parsing uses getRawAuthority() rather than the percent-decoded
    getAuthority(), so a password containing an encoded :, , or @
    is not mistaken for a delimiter. Decoding happens after splitting,
    matching the existing parseUserinfo() behaviour.
  • PostgresqlJdbcUrlCreator uses getHostAndPort() so every host
    survives into the generated JDBC URL.
  • MySqlJdbcUrlCreator does the same. MySQL and MariaDB support the same
    host1,host2 failover syntax, and it shares the UriInfo code path, so
    without this it would have silently emitted a first-host-only URL.
  • Authorities that fail server-based parsing without containing a comma
    (for example SQL Server’s ;property=value suffix) keep their previous
    behaviour and continue to be handled by their own creator.

Tests

  • UriInfoTests: multi-host with and without userinfo, a percent-encoded
    : in the password, a non-PostgreSQL (mysql) multi-host authority, and
    a single-host case asserting the standard path is unaffected.
  • PostgresqlJdbcTests / MySqlJdbcTests: end-to-end VCAP_SERVICES
    payloads asserting all hosts reach the JDBC URL.

@kvmw kvmw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@pivotal-david-osullivan
pivotal-david-osullivan deleted the postgres-multi-host branch August 12, 2026 15:34
@pivotal-david-osullivan
pivotal-david-osullivan restored the postgres-multi-host branch August 12, 2026 15:36
@pivotal-david-osullivan pivotal-david-osullivan changed the title Support for multiple hosts with postgres Support multiple hosts for PostgreSQL and MySQL Aug 12, 2026
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.

2 participants