Re: Proposal: Implement failover on libpq connect level.

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, Andres Freund <andres(at)anarazel(dot)de>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, Victor Wagner <vitus(at)wagner(dot)pp(dot)ru>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal: Implement failover on libpq connect level.
Date: 2015-09-08 22:21:02
Message-ID: CA+TgmoZqQ9+VMFHASDcEtz_qF4nHYqcCq1P1-z7M2+82pz2vWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-jdbc

On Tue, Sep 8, 2015 at 9:29 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> I'm not saying we shouldn't have something like this; but we need a
> clear definition of that common problem we are solving. I don't
> think I've seen that yet. I've seen various spins on solutions
> described, from which I can infer various possible problems; but to
> pick the best version of this as *the* solution I think we need a
> clear statement of the problem itself.

I think the problem we should be trying to solve is: Given a set of
server IPs, connect to one that is up.

I believe this comes up in several different scenarios.

Example #1: I need to move my database server to a different IP
address. I could have clients connect by name, but using DNS sucks
for the reasons already discussed. I could move the server and then
change all the client connect strings afterwards, but then I'm bound
to be down for longer than necessary. Instead, I'll change all of my
connect strings FIRST, to specify that either IP is acceptable. Then
I'll move the server to the new IP, and all of them will quickly find
that the old IP is down and the new IP is up and start using that
instead. At leisure, I can remove the old IP from connect strings
(and then re-purpose that IP).

Example #2: I am using EnterpriseDB's xDB multi-master replication, or
2ndQuadrant's BDR, to replicate among geographically distributed
database servers. I want clients to connect to their local server,
but if it is down, I want them to connect to one of the other masters.
Connecting to the local server first minimizes replication conflicts,
since most transactions on a given application server will be for data
local to that geography, but being willing to fall back to some other
server maximizes availability when my local server goes down.

Example #3: I have a master and and 3 SR standbys, all on different
subnets. Periodically, I fail over, so that the master role moves
around. Each server has an IP which can be used for read-only
connections. Each also has a virtual IP which is up when it is the
write master and down when it is a standby. Read-only queries are 90%
of my traffic, and eventual consistency is fine. So, for a read
query, I want to pick among the IPs that are up; for write IPs, I want
to find the one place that writes can be performed, but that might be
any of 4 virtual IPs.

I'm sure there are more.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2015-09-08 23:21:07 Re: Summary of plans to avoid the annoyance of Freezing
Previous Message Thom Brown 2015-09-08 22:00:48 Re: [PATCH] Microvacuum for gist.

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kevin Grittner 2015-09-09 20:30:49 Re: Proposal: Implement failover on libpq connect level.
Previous Message Kevin Grittner 2015-09-08 13:29:12 Re: Proposal: Implement failover on libpq connect level.