sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.44k stars 436 forks source link

Question: LoadBalancing #1019

Closed cemremengu closed 1 year ago

cemremengu commented 1 year ago

Does this driver support specifying LoadBalance option like the JDBC driver?

loadBalanceHosts = boolean

In default mode (disabled) hosts are connected in the given order. If enabled hosts are chosen randomly from the set of suitable candidates.
sfackler commented 1 year ago

I don't believe something like that is currently exposed. If libpq offers similar functionality we could mirror that here.

sfackler commented 1 year ago

You can also shuffle the hosts list yourself depending on how your code is set up.

cemremengu commented 1 year ago

Thanks for the quick reply. I think libpq does not support it yet but as far as I understand its around the corner (or already released)

https://commitfest.postgresql.org/38/3679/

sfackler commented 1 year ago

Ah cool. Once that API is stabilized we can reflect it here.

fritshoogland-yugabyte commented 1 year ago

This would be an awesome feature that can save a lot of people from having to use haproxy or pgcat just for this functionality!

fritshoogland-yugabyte commented 1 year ago

Load balancing is added to postgresql version 16: https://www.postgresql.org/docs/16/libpq-connect.html