pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Failover Datasource?
13+ messages / 8 participants
[nested] [flat]

* Re: Failover Datasource?
@ 2011-06-16 19:33  Bruce Adams <bruce.adams@acm.org>
  0 siblings, 1 reply; 13+ messages in thread

From: Bruce Adams @ 2011-06-16 19:33 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Tim H <drgonzo1337@gmail.com>

I, too, would like to be able to specify multiple Postgres servers in a 
JDBC connection URL. I want the client application to prefer connecting 
to a master database, but automatically failover to a replica when the 
master is unavailable.

Many other databases have this feature in their JDBC drivers. For 
example a MySQL JDBC URL can have a comma separated list of host:port in 
the URL, like this:
           jdbc:mysql://master:3306,slave:3306/databasename

Is there some other way to setup client failover?

Writings I've found for Postgres always talk about a proxy, or even 
multiple proxies (!), between the Java client and the real database 
servers. I'm trying to build a robust system; any additional layer is 
yet another thing that can break. I don't mind having the application 
see errors in a failover, I just want some measure of recovery to be 
automatic, even if the automatic recovery is to a read-only replica.

I plan to use streaming replication in PostgreSQL 9.0 for the hot backup(s).

- Bruce

On Tue, 15 Apr 2008 10:12:07 -0400, Tim H wrote:
> I'd like to create a pooling JDBC datasource that can handle failing 
> over to an alternate URL.
>
> I've seen drivers from other vendors that allow you to pass in two 
> databases in the connection URL. I've scoured the mailing list here 
> and haven't found a thing.
>
> Can someone point me in the right direction?
>
> Thanks,
> Tim
>
> -- 
> ./tch




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-16 19:56  Thomas Kellerer <spam_eater@gmx.net>
  parent: Bruce Adams <bruce.adams@acm.org>
  0 siblings, 1 reply; 13+ messages in thread

From: Thomas Kellerer @ 2011-06-16 19:56 UTC (permalink / raw)
  To: pgsql-jdbc

Bruce Adams wrote on 16.06.2011 21:33:
> I, too, would like to be able to specify multiple Postgres servers in
> a JDBC connection URL. I want the client application to prefer
> connecting to a master database, but automatically failover to a
> replica when the master is unavailable.
>
> Many other databases have this feature in their JDBC drivers. For
> example a MySQL JDBC URL can have a comma separated list of host:port
> in the URL, like this:
> jdbc:mysql://master:3306,slave:3306/databasename
>
> Is there some other way to setup client failover?
>
> Writings I've found for Postgres always talk about a proxy, or even
> multiple proxies (!), between the Java client and the real database
> servers. I'm trying to build a robust system; any additional layer is
> yet another thing that can break. I don't mind having the application
> see errors in a failover, I just want some measure of recovery to be
> automatic, even if the automatic recovery is to a read-only replica.
>
> I plan to use streaming replication in PostgreSQL 9.0 for the hot
> backup(s).

pgBouncer or pgPool can both do that as far as I know

http://wiki.postgresql.org/wiki/PgBouncer
http://pgpool.projects.postgresql.org/

Thomas






^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-16 20:27  Bruce Adams <bruce.adams@acm.org>
  parent: Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 2 replies; 13+ messages in thread

From: Bruce Adams @ 2011-06-16 20:27 UTC (permalink / raw)
  To: pgsql-jdbc

Both pgBouncer and pgPool add another process between the client and the 
server.

Their primary goal appears to be connection pooling. My Java application 
server (Apache Tomcat) is already pooling database connections.

Adding another chunk of middle-ware adds another thing I have to worry 
about failing and is likely to slow things down.

If I write code to add failover support into the JDBC driver, what are 
my chances of getting that patch into the next release?

- Bruce

On 06/16/2011 03:56 PM, Thomas Kellerer wrote:
> Bruce Adams wrote on 16.06.2011 21:33:
>> I, too, would like to be able to specify multiple Postgres servers in 
>> a JDBC connection URL. I want the client application to prefer 
>> connecting to a master database, but automatically failover to a 
>> replica when the master is unavailable.
>>
>> Many other databases have this feature in their JDBC drivers. For 
>> example a MySQL JDBC URL can have a comma separated list of host:port 
>> in the URL, like this:
>> jdbc:mysql://master:3306,slave:3306/databasename
>>
>> Is there some other way to setup client failover?
>>
>> Writings I've found for Postgres always talk about a proxy, or even 
>> multiple proxies (!), between the Java client and the real database 
>> servers. I'm trying to build a robust system; any additional layer is
>> yet another thing that can break. I don't mind having the application 
>> see errors in a failover, I just want some measure of recovery to be 
>> automatic, even if the automatic recovery is to a read-only replica.
>>
>> I plan to use streaming replication in PostgreSQL 9.0 for the hot 
>> backup(s).
>
> pgBouncer or pgPool can both do that as far as I know
>
> http://wiki.postgresql.org/wiki/PgBouncer
> http://pgpool.projects.postgresql.org/
>
> Thomas



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-16 20:35  Thomas Kellerer <spam_eater@gmx.net>
  parent: Bruce Adams <bruce.adams@acm.org>
  1 sibling, 0 replies; 13+ messages in thread

From: Thomas Kellerer @ 2011-06-16 20:35 UTC (permalink / raw)
  To: pgsql-jdbc

Bruce Adams wrote on 16.06.2011 22:27:
> Both pgBouncer and pgPool add another process between the client and
> the server.
>
> Their primary goal appears to be connection pooling. My Java
> application server (Apache Tomcat) is already pooling database
> connections.

Especially pgPool (despite the name) is more than "just" a connection pooler.

Thomas




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-16 23:51  John R Pierce <pierce@hogranch.com>
  parent: Bruce Adams <bruce.adams@acm.org>
  1 sibling, 1 reply; 13+ messages in thread

From: John R Pierce @ 2011-06-16 23:51 UTC (permalink / raw)
  To: pgsql-jdbc

On 06/16/11 1:27 PM, Bruce Adams wrote:
> Their primary goal appears to be connection pooling. My Java 
> application server (Apache Tomcat) is already pooling database 
> connections. 

I think JDBC is the wrong layer for this, instead it should be 
implemented in your java connection pool (tomcat, etc), where you 
configure it with the multiple connections and the connection pooling 
rules (master/failover, vs round robin vs whatever).


-- 
john r pierce                            N 37, W 122
santa cruz ca                         mid-left coast




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-17 01:55  Bruce Adams <bruce.adams@acm.org>
  parent: John R Pierce <pierce@hogranch.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Bruce Adams @ 2011-06-17 01:55 UTC (permalink / raw)
  To: pgsql-jdbc

In principal, I agree; in practice, that's not the way it's been done in 
the Java application server world.

I have two readily available Java database connection pool 
implementations available: the one bundled with Apache Tomcat and 
Hibernate's c3p0. Neither of these directly support failover. They each 
expect the lower level JDBC driver to deal with failover. (This is true 
of BEA WebLogic and IBM WebSphere as well, at least as of a few years 
ago when I last used them intensely.)

What I'm looking for is very standard stuff in the Java application 
server world. The JDBC driver handles failover and/or load balancing to 
multiple backend database servers.

- Bruce

On 06/16/2011 07:51 PM, John R Pierce wrote:
> On 06/16/11 1:27 PM, Bruce Adams wrote:
>> Their primary goal appears to be connection pooling. My Java 
>> application server (Apache Tomcat) is already pooling database 
>> connections 
>
> I think JDBC is the wrong layer for this, instead it should be 
> implemented in your java connection pool (tomcat, etc), where you 
> configure it with the multiple connections and the connection pooling 
> rules (master/failover, vs round robin vs whatever).



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-17 02:02  John R Pierce <pierce@hogranch.com>
  parent: Bruce Adams <bruce.adams@acm.org>
  0 siblings, 1 reply; 13+ messages in thread

From: John R Pierce @ 2011-06-17 02:02 UTC (permalink / raw)
  To: pgsql-jdbc

On 06/16/11 6:55 PM, Bruce Adams wrote:
> In principal, I agree; in practice, that's not the way it's been done 
> in the Java application server world.
>
> I have two readily available Java database connection pool 
> implementations available: the one bundled with Apache Tomcat and 
> Hibernate's c3p0. Neither of these directly support failover. They 
> each expect the lower level JDBC driver to deal with failover. (This 
> is true of BEA WebLogic and IBM WebSphere as well, at least as of a 
> few years ago when I last used them intensely.)
>
> What I'm looking for is very standard stuff in the Java application 
> server world. The JDBC driver handles failover and/or load balancing 
> to multiple backend database servers.

it just seems to me that the individual client drivers shouldn't be what 
is tracking the state of the server cluster.    I can't imagine the 
driver layer could do more than 'try connecting to server 1, if that 
fails, try server 2'...  if server 1 is dead and not responding, this is 
going to be painfully slow and result in minute long TCP connection 
timeouts on each connect.

Do oracle jdbc drivers support this multiple-server notation, same as 
shown here earlier for mysql?

-- 
john r pierce                            N 37, W 122
santa cruz ca                         mid-left coast




^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2011-06-17 02:20  Bruce Adams <bruce.adams@acm.org>
  parent: John R Pierce <pierce@hogranch.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Bruce Adams @ 2011-06-17 02:20 UTC (permalink / raw)
  To: pgsql-jdbc

Yes, Oracle's JDBC drivers support insanely long JDBC URLs which allow 
specifying a whole cluster of database servers, what the failover 
policies are, including various timeouts, load balance weights and more. 
A single JDBC URL for Oracle can be a thousand characters or more. I 
suspect the other database vendors (I specifically know about IBM DB2 
and MySQL) have followed Oracle's lead here.

This page has a simple example:
http://programmersjournal.blogspot.com/2008/08/jdbc-connection-string-for-oracle-rac.html

On 06/16/2011 10:02 PM, John R Pierce wrote:
> On 06/16/11 6:55 PM, Bruce Adams wrote:
>> In principal, I agree; in practice, that's not the way it's been done 
>> in the Java application server world.
>>
>> I have two readily available Java database connection pool 
>> implementations available: the one bundled with Apache Tomcat and 
>> Hibernate's c3p0. Neither of these directly support failover. They 
>> each expect the lower level JDBC driver to deal with failover. (This 
>> is true of BEA WebLogic and IBM WebSphere as well, at least as of a 
>> few years ago when I last used them intensely.)
>>
>> What I'm looking for is very standard stuff in the Java application 
>> server world. The JDBC driver handles failover and/or load balancing 
>> to multiple backend database servers.
>
> it just seems to me that the individual client drivers shouldn't be 
> what is tracking the state of the server cluster.    I can't imagine 
> the driver layer could do more than 'try connecting to server 1, if 
> that fails, try server 2'...  if server 1 is dead and not responding, 
> this is going to be painfully slow and result in minute long TCP 
> connection timeouts on each connect.
>
> Do oracle jdbc drivers support this multiple-server notation, same as 
> shown here earlier for mysql?
>



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2012-04-10 11:09  tsaixingwei <tsaixingwei@gmail.com>
  parent: Bruce Adams <bruce.adams@acm.org>
  0 siblings, 1 reply; 13+ messages in thread

From: tsaixingwei @ 2012-04-10 11:09 UTC (permalink / raw)
  To: pgsql-jdbc

Bruce,
I was looking for the same thing you are in the Postgresql JDBC driver.
Judging from the silence on this thread since your last post, I'm guessing
this feature won't be in the Postgresql JDBC driver anytime soon.

I'm trying out something else at the moment - HAJDBC - which is multi-master
replication instead of master-slave replication and it is implemented in a
JDBC driver itself. See this: http://ha-jdbc.sourceforge.net/



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Re-Failover-Datasource-tp4496411p5629626.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2012-12-12 09:09  kaprikorn07 <bharath.spyk@gmail.com>
  parent: tsaixingwei <tsaixingwei@gmail.com>
  0 siblings, 1 reply; 13+ messages in thread

From: kaprikorn07 @ 2012-12-12 09:09 UTC (permalink / raw)
  To: pgsql-jdbc

Hi All,

As Bruce Adams has mentioned, please let me know if there is any other way
to do it other than pgBouncer and pgPool.

Please help!



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Re-Failover-Datasource-tp4496411p5736270.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2012-12-12 10:41  Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
  parent: kaprikorn07 <bharath.spyk@gmail.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Mikko Tiihonen @ 2012-12-12 10:41 UTC (permalink / raw)
  To: kaprikorn07 <bharath.spyk@gmail.com>; pgsql-jdbc

With latest jdbc drivers you can simply configure multiple host:port pairs in the url separated by comma:

jdbc:postgresql://host1:port1,host2:port2/test

It has only the most basic failover support. When a new connection is opened the hosts are tried in round-robin until a connection is successfully established.

-Mikko
________________________________________
From: pgsql-jdbc-owner@postgresql.org [pgsql-jdbc-owner@postgresql.org] on behalf of kaprikorn07 [bharath.spyk@gmail.com]
Sent: 12 December 2012 11:09
To: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] Failover Datasource?

Hi All,

As Bruce Adams has mentioned, please let me know if there is any other way
to do it other than pgBouncer and pgPool.

Please help!



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Re-Failover-Datasource-tp4496411p5736270.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2012-12-12 10:49  Dave Cramer <pg@fastcrypt.com>
  parent: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Dave Cramer @ 2012-12-12 10:49 UTC (permalink / raw)
  To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; +Cc: kaprikorn07 <bharath.spyk@gmail.com>; pgsql-jdbc

Mikko,

I can't recall did you ever provide a documentation patch for this ?

Dave

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca



On Wed, Dec 12, 2012 at 5:41 AM, Mikko Tiihonen <
Mikko.Tiihonen@nitorcreations.com> wrote:

> With latest jdbc drivers you can simply configure multiple host:port pairs
> in the url separated by comma:
>
> jdbc:postgresql://host1:port1,host2:port2/test
>
> It has only the most basic failover support. When a new connection is
> opened the hosts are tried in round-robin until a connection is
> successfully established.
>
> -Mikko
> ________________________________________
> From: pgsql-jdbc-owner@postgresql.org [pgsql-jdbc-owner@postgresql.org]
> on behalf of kaprikorn07 [bharath.spyk@gmail.com]
> Sent: 12 December 2012 11:09
> To: pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] Failover Datasource?
>
> Hi All,
>
> As Bruce Adams has mentioned, please let me know if there is any other way
> to do it other than pgBouncer and pgPool.
>
> Please help!
>
>
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/Re-Failover-Datasource-tp4496411p5736270.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: Failover Datasource?
@ 2012-12-12 15:06  Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 13+ messages in thread

From: Mikko Tiihonen @ 2012-12-12 15:06 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: kaprikorn07 <bharath.spyk@gmail.com>; pgsql-jdbc

On 12/12/2012 12:49 PM, Dave Cramer wrote:
> Mikko,
>
> I can't recall did you ever provide a documentation patch for this ?

I'm not sure, but I still found the patch that I was supposed to send... attached.

-Mikko

> On Wed, Dec 12, 2012 at 5:41 AM, Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com <mailto:Mikko.Tiihonen@nitorcreations.com>> wrote:
>
>     With latest jdbc drivers you can simply configure multiple host:port pairs in the url separated by comma:
>
>     jdbc:postgresql://host1:port1,host2:port2/test
>
>     It has only the most basic failover support. When a new connection is opened the hosts are tried in round-robin until a connection is successfully established.
>
>     -Mikko
>     ________________________________________
>     From: pgsql-jdbc-owner@postgresql.org <mailto:pgsql-jdbc-owner@postgresql.org> [pgsql-jdbc-owner@postgresql.org <mailto:pgsql-jdbc-owner@postgresql.org>] on
>     behalf of kaprikorn07 [bharath.spyk@gmail.com <mailto:bharath.spyk@gmail.com>]
>     Sent: 12 December 2012 11:09
>     To: pgsql-jdbc@postgresql.org <mailto:pgsql-jdbc@postgresql.org>
>     Subject: Re: [JDBC] Failover Datasource?
>
>     Hi All,
>
>     As Bruce Adams has mentioned, please let me know if there is any other way
>     to do it other than pgBouncer and pgPool.
>
>     Please help!
>
>
>
>     --
>     View this message in context: http://postgresql.1045698.n5.nabble.com/Re-Failover-Datasource-tp4496411p5736270.html
>     Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
>     --
>     Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org <mailto:pgsql-jdbc@postgresql.org>)
>     To make changes to your subscription:
>     http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
>     --
>     Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org <mailto:pgsql-jdbc@postgresql.org>)
>     To make changes to your subscription:
>     http://www.postgresql.org/mailpref/pgsql-jdbc
>
>

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

connection-failover-documentation.patch (text/x-patch, 1.4K) download diff --git a/doc/pgjdbc.xml b/doc/pgjdbc.xml index a13d320..10d7e5f 100644 --- a/doc/pgjdbc.xml +++ b/doc/pgjdbc.xml @@ -812,6 +812,31 @@ openssl pkcs8 -topk8 -in client.key -out client.pk8 -outform DER -v1 PBE-SHA1-3D </sect2> + <sect2 id="connection-failover"> + <title>Connection Fail-over</title> + + <para> + To support simple connection fail-over it is possible to define multiple + endpoints (host and port pairs) in the connection url separated by commas. + The driver will try to once connect to each of them in order until the + connection succeeds. If none succeed, a normal connection exception is + thrown. + </para> + <para> + The syntax for the connection url is: + <synopsis> +jdbc:postgresql://<replaceable class="parameter">host1</replaceable>:<replaceable class="parameter">port1</replaceable>,<replaceable class="parameter">host2</replaceable>:<replaceable class="parameter">port2</replaceable>/<replaceable class="parameter">database</replaceable> +</synopsis> + </para> + + <para> + The simple connection fail-over is useful when running against + a high availability postgres installation that has identical data on each node. + For example streaming replication postgres that only accepts connection on the master + node or postgres-xc cluster. + </para> + </sect2> + </sect1> </chapter>
^ permalink raw reply [nested|flat] 13+ messages in thread


end of thread, other threads:[~2012-12-12 15:06 UTC | newest]

Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-16 19:33 Re: Failover Datasource? Bruce Adams <bruce.adams@acm.org>
2011-06-16 19:56 ` Thomas Kellerer <spam_eater@gmx.net>
2011-06-16 20:27   ` Bruce Adams <bruce.adams@acm.org>
2011-06-16 20:35     ` Thomas Kellerer <spam_eater@gmx.net>
2011-06-16 23:51     ` John R Pierce <pierce@hogranch.com>
2011-06-17 01:55       ` Bruce Adams <bruce.adams@acm.org>
2011-06-17 02:02         ` John R Pierce <pierce@hogranch.com>
2011-06-17 02:20           ` Bruce Adams <bruce.adams@acm.org>
2012-04-10 11:09             ` tsaixingwei <tsaixingwei@gmail.com>
2012-12-12 09:09               ` kaprikorn07 <bharath.spyk@gmail.com>
2012-12-12 10:41                 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-12-12 10:49                   ` Dave Cramer <pg@fastcrypt.com>
2012-12-12 15:06                     ` Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>

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