I tried to stay in line with the naming of this same option in JDBC and Npgsql, where it's called "loadBalanceHosts" and "Load Balance Hosts" respectively. So, actually to be more in line it should be the option for libpq should be called "load_balance_hosts" (not "loadbalance" like in the previous patch). I attached a new patch with the name of the option changed to this.
I also don't think the name is misleading. Randomization of hosts will automatically result in balancing the load across multiple hosts. This is assuming more than a single connection is made using the connection string, either on the same client node or on different client nodes. I think I think is a fair assumption to make. Also note that this patch does not load balance queries, it load balances connections. This is because libpq works at the connection level, not query level, due to session level state. I agree it is indeed fairly simplistic load balancing. But many dedicated load balancers often use simplistic load balancing too. Round-robin, random and hash+modulo based load balancing are all very commonly used load balancer strategies. Using this patch you should even be able to implement the weighted load balancing that you suggest, by supplying the same host + port pair multiple times in the list of hosts. My preference would be to use load_balance_hosts for the option name. However, if the name of the option becomes the main point of contention I would be fine with changing the option to "randomize_hosts". I think in the end it comes down to what we want the name of the option to reflect: 1. load_balance_hosts reflects what you (want to) achieve by enabling it 2. randomize_hosts reflects how it is achieved Jelte
0001-Support-load-balancing-in-libpq.patch
Description: 0001-Support-load-balancing-in-libpq.patch