setPortNumber() should not be used when useing connection fail-overfeature with PGConnectionPoolDataSource? - Mailing list pgsql-jdbc

From Okano, Naoki
Subject setPortNumber() should not be used when useing connection fail-overfeature with PGConnectionPoolDataSource?
Date
Msg-id 0B4917A40C80E34BBEC4BE1A7A9AB7E2A836C6@g01jpexmbkw05
Whole thread Raw
Responses Re: setPortNumber() should not be used when useing connectionfail-over feature with PGConnectionPoolDataSource?
List pgsql-jdbc
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: Dave Cramer
Date:
Subject: [pgjdbc/pgjdbc] c0f6b9: Fix formatting
Next
From: Craig Ringer
Date:
Subject: [pgjdbc/pgjdbc] 72dc69: Update waffle-jna to new artifact coordinates(#13...