Skip to content

Conversation

@arp242
Copy link
Collaborator

@arp242 arp242 commented Jan 22, 2026

Similar to libpq, you can now use multiple values in host, hostaddr, and port to try more than one server to connect to:

host=pg.localhost,backup.localhost

Additional hosts are added to Config.Multi. I originally looked at changing Config.{Host,Hostaddr,Port} to a slice, but I found this awkward to use both in the code here and as a client. I also looked at using a []Config, which I found similarly awkward.

Putting additional hosts in a separate struct field keeps things straight-forward for the common use case (just one host), and with the hosts() method it's fairly straight-forward to use. hosts() is not exported because it assumes Config is correctly validated, and I'm not sure if it's really useful for anyone else. But if there's a use-case for it then it can be exported.

Fixes #683
Closes #714

Similar to libpq, you can now use multiple values in host, hostaddr, and
port to try more than one server to connect to:

	host=pg.localhost,backup.localhost

Additional hosts are added to Config.Multi. I originally looked at
changing Config.{Host,Hostaddr,Port} to a slice, but I found this
awkward to use both in the code here and as a client. I also looked at
using a []Config, which I found similarly awkward.

Putting additional hosts in a separate struct field keeps things
straight-forward for the common use case (just one host), and with the
hosts() method it's fairly straight-forward to use. hosts() is not
exported because it assumes Config is correctly validated, and I'm not
sure if it's really useful for anyone else. But if there's a use-case
for it then it can be exported.

Fixes #683
Closes #714
@arp242 arp242 force-pushed the multi branch 2 times, most recently from 7bfb5be to 3538233 Compare January 23, 2026 16:16
Applies both connecting to a single host ("host=localhost") and multiple
hosts ("host=one,two").
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.

add support for multiple hosts in connection settings (for feature parity with libpq)

2 participants