pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Ramseyer <rc@networkz.ch>
To: pgsql-general@postgresql.org
Subject: Can I tell libpq to connect to the primary?
Date: Wed, 22 Apr 2020 21:10:35 +0200
Message-ID: <da508681-20be-1741-3bb1-25910ca22ae1@networkz.ch> (raw)

Hi

I'm setting up a new environment with a primary/hot standby replication
pair.

For read-only clients, I have found the host=host1,host2 connection
string[1] which allows a connection when any one of the servers is up.

However I'm unsure how to achieve something similar for read/write
clients. If I'm providing this list, the client will connect to the
first host, which might have become the standby in the meantime.

I see that in pgjdbc there are additional options for targetServerType =
any, primary, secondary, preferSlave and preferSecondary[2]. However
this seems to be java-specific and not implemented in libpq? Is there a
way to get this behaviour in PHP/Psycopg/Perl DBI?

If not, what is the best alternative to achieve this? My primary &
standby are not in the same L3 network, so moving around and IP address
with Linux OS clustering is not an option. I'm tending to scripting the
REST API of our DNS service to point a CNAME at the new primary during
promotion, but maybe there is an easier way I haven't found yet? Maybe
something in pgpool/pgbouncer etc?


Cheers
Christian

[1] https://www.postgresql.org/docs/current/libpq-connect.html
[2] https://jdbc.postgresql.org/documentation/head/connect.html





view thread (3+ messages)  latest in thread

Message-ID: <da508681-20be-1741-3bb1-25910ca22ae1@networkz.ch>
Permalink:  ../da508681-20be-1741-3bb1-25910ca22ae1@networkz.ch/
Also on:    postgresql.org/message-id/da508681-20be-1741-3bb1-25910ca22ae1@networkz.ch

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rc@networkz.ch
  Subject: Re: Can I tell libpq to connect to the primary?
  In-Reply-To: <da508681-20be-1741-3bb1-25910ca22ae1@networkz.ch>
  References: <da508681-20be-1741-3bb1-25910ca22ae1@networkz.ch>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox