From: | Mikko Tiihonen <Mikko(dot)Tiihonen(at)nitorcreations(dot)com> |
---|---|
To: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | [PATCH] libpq: Allow specifying multiple host names to try to connect to |
Date: | 2015-04-19 15:18:10 |
Message-ID: | 1429456689719.46797@nitorcreations.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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
Attachment | Content-Type | Size |
---|---|---|
libpq_multiple_hosts.patch | text/x-patch | 3.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tomas Vondra | 2015-04-19 20:51:53 | alternative compression algorithms? |
Previous Message | Michael Paquier | 2015-04-19 13:01:40 | Re: Supporting TAP tests with MSVC and Windows |