Hi,
I would like allow specifying multiple host names for libpq to try to connecting to. This is currently only supported if the host name resolves to multiple addresses. Having the support for it without complex dns setup would be much easier.
Example:
psql -h dbslave,dbmaster -p 5432 dbname
psql 'postgresql://dbslave,dbmaster:5432/dbname'
Here the idea is that without any added complexity of pgbouncer or similar tool I can get any libpq client to try connecting to multiple nodes until one answers. I have added the similar functionality to the jdbc driver few years ago.
Because libpq almost supported the feature already the patch is very simple. I just split the given host name and do a dns lookup on each separately, and link the results.
If you configure a port that does not exist you can see the libpq trying to connect to multiple hosts.
psql -h 127.0.0.2,127.0.0.3, -p 5555
psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.2,127.0.0.3" (127.0.0.2) and accepting
TCP/IP connections on port 5555?
could not connect to server: Connection refused
Is the server running on host "127.0.0.2,127.0.0.3" (127.0.0.3) and accepting
TCP/IP connections on port 5555?
Further improvement would be to add a connection parameter to limit connection only to master (writable) or to slave (read only).
-Mikko