Re: setPortNumber() should not be used when useing connectionfail-over feature with PGConnectionPoolDataSource? - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: setPortNumber() should not be used when useing connectionfail-over feature with PGConnectionPoolDataSource?
Date
Msg-id CADK3HHJ0EUmj6iPJdUW0zuad-xsraOv89QPENYAkhDjhgXgLig@mail.gmail.com
Whole thread Raw
In response to setPortNumber() should not be used when useing connection fail-overfeature with PGConnectionPoolDataSource?  ("Okano, Naoki" <okano.naoki@jp.fujitsu.com>)
Responses RE: setPortNumber() should not be used when useing connectionfail-over feature with PGConnectionPoolDataSource?
List pgsql-jdbc
Pretty sure this was never intended to work.

That said if you can provide a pull request we can look at implementing it.

On Mon, 7 Jan 2019 at 05:07, Okano, Naoki <okano.naoki@jp.fujitsu.com> wrote:
Hi,

I want to use connection fail-over feature with PGConnectionPoolDataSource.
(In this time, I does not use DriverManager.)

When specifying multiple hosts for the serverName property
and using setPortNumber() with PGConnectionPoolDataSource,
it does not work well. Please show cases (2) and (3) below.

So, when I use connection fail-over feature with PGConnectionPoolDataSource,
I think setPortNumber() should not be used. Is my understanding correct?

I show my environment and testing cases.

[My environment]
There are two hosts, host1 and host2.
They have Postgres with port 5433 (not default port).

[My test cases]
case (1):
  Specifying host and port pairs for the serverName property,
  An example of code is as follows.
    PGConnectionPoolDataSource source = new PGConnectionPoolDataSource();
    source.setServerName("host1:5433,host2:5433");
    conn = source.getConnection();
  This works well. I can connect to both host1 and host2 correctly.

case (2):
  Specifying multiple hosts for the serverName property and then specifying portNumber.
  An example of code is as follows.
    PGConnectionPoolDataSource source = new PGConnectionPoolDataSource();
    source.setServerName("host1,host2");
    source.setPortNumber(5433);
    conn = source.getConnection();
  This does not work well.
  Connection to host2 is succeeded, but conection to host1 always fails.
  In this case, source.getUrl() shows "jdbc:postgresql://host1,host2:5433...".
  I hope source.getUrl() shows "jdbc:postgresql://host1:5433,host2:5433...",
  but connection to host1 uses default port.

case (3):
  Specify host and port pairs for the serverName property, and then Specify portNumber.
  An example of code is as follows.
    PGConnectionPoolDataSource source = new PGConnectionPoolDataSource();
    source.setServerName("host1:5433,host2:5433");
    source.setPortNumber(5433);
    conn = source.getConnection();
  This does not work well.
  Connection to host1 is succeeded, but conection to host2 fails.
  In this case, source.getUrl() shows "jdbc:postgresql://host1:5433,host2:5433:5433...".
  host2:5433:5433 is clearly wrong.

Regards,
Okano Naoki



pgsql-jdbc by date:

Previous
From: Craig Ringer
Date:
Subject: [pgjdbc/pgjdbc] 72dc69: Update waffle-jna to new artifact coordinates(#13...
Next
From: "Okano, Naoki"
Date:
Subject: RE: setPortNumber() should not be used when useing connectionfail-over feature with PGConnectionPoolDataSource?