Thread: setPortNumber() should not be used when useing connection fail-overfeature with PGConnectionPoolDataSource?

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




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



Dave Cramer [mailto:pg@fastcrypt.com] wrote:
> Pretty sure this was never intended to work.
>
>
> That said if you can provide a pull request we can look at implementing it.

Thank you for your reply!
I understand it does not work as intended.
So, I try to implement it and will send a pull request.

Regards,
Okano Naoki

To be honest, we've not put a lot of work into pooling implementations as there are far better ones out there.

That being said, there aren't good ones that do automatic failover so perhaps there is some utility in it



On Tue, 8 Jan 2019 at 03:09, Okano, Naoki <okano.naoki@jp.fujitsu.com> wrote:
Dave Cramer [mailto:pg@fastcrypt.com] wrote:
> Pretty sure this was never intended to work.
>
>
> That said if you can provide a pull request we can look at implementing it.

Thank you for your reply!
I understand it does not work as intended.
So, I try to implement it and will send a pull request.

Regards,
Okano Naoki