Support connection load balancing in libpq
authorDaniel Gustafsson <[email protected]>
Wed, 29 Mar 2023 19:53:38 +0000 (21:53 +0200)
committerDaniel Gustafsson <[email protected]>
Wed, 29 Mar 2023 19:53:38 +0000 (21:53 +0200)
commit7f5b19817eaf38e70ad1153db4e644ee9456853e
treeae454d99c6e725fff3f0e259c3d0118a83ffd44d
parent44d85ba5a3361dea371d23bd91777ef4c0c4e506
Support connection load balancing in libpq

This adds support for load balancing connections with libpq using a
connection parameter: load_balance_hosts=<string>. When setting the
param to random, hosts and addresses will be connected to in random
order. This then results in load balancing across these addresses and
hosts when multiple clients or frequent connection setups are used.

The randomization employed performs two levels of shuffling:

  1. The given hosts are randomly shuffled, before resolving them
     one-by-one.
  2. Once a host its addresses get resolved, the returned addresses
     are shuffled, before trying to connect to them one-by-one.

Author: Jelte Fennema <[email protected]>
Reviewed-by: Aleksander Alekseev <[email protected]>
Reviewed-by: Michael Banck <[email protected]>
Reviewed-by: Andrey Borodin <[email protected]>
Discussion: https://postgr.es/m/PR3PR83MB04768E2FF04818EEB2179949F7A69@PR3PR83MB0476.EURPRD83.prod.outlook.
.cirrus.yml
doc/src/sgml/libpq.sgml
doc/src/sgml/regress.sgml
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/libpq-int.h
src/interfaces/libpq/meson.build
src/interfaces/libpq/t/003_load_balance_host_list.pl [new file with mode: 0644]
src/interfaces/libpq/t/004_load_balance_dns.pl [new file with mode: 0644]
src/test/perl/PostgreSQL/Test/Cluster.pm
src/tools/pgindent/typedefs.list