Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1I9V-0007le-NW for pgsql-jdbc@arkaria.postgresql.org; Mon, 22 Jul 2013 15:35:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V1I9V-0006Hy-6L for pgsql-jdbc@arkaria.postgresql.org; Mon, 22 Jul 2013 15:35:57 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1I9U-0006HU-6J for pgsql-jdbc@postgresql.org; Mon, 22 Jul 2013 15:35:56 +0000 Received: from mail-relay1.slovanet.net ([195.80.175.70]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1I9O-0005Wi-Kp for pgsql-jdbc@postgresql.org; Mon, 22 Jul 2013 15:35:55 +0000 Received: from localhost (localhost [127.0.0.1]) by mail-relay1.slovanet.net (Postfix) with ESMTP id AF3B6580CFB for ; Mon, 22 Jul 2013 17:35:49 +0200 (CEST) X-Virus-Scanned: at Slovanet mail-relay Received: from mailhub2.slovanet.net (mailhub1.slovanet.net [195.28.64.118]) by mail-relay1.slovanet.net (Postfix) with ESMTP id 60AEB580CD4 for ; Mon, 22 Jul 2013 17:35:47 +0200 (CEST) Received: from mail.virte.sk (unknown [195.80.190.222]) by mailhub2.slovanet.net (Postfix) with ESMTP id 250B28D2FBD for ; Mon, 22 Jul 2013 17:35:47 +0200 (CEST) Received: from ELECTRA.virte.intra (192.168.17.25) by Electra.virte.intra (192.168.17.25) with Microsoft SMTP Server (TLS) id 15.0.620.29; Mon, 22 Jul 2013 17:35:46 +0200 Received: from ELECTRA.virte.intra ([::1]) by Electra.virte.intra ([::1]) with mapi id 15.00.0620.020; Mon, 22 Jul 2013 17:35:46 +0200 From: Mistina Michal To: "pgsql-jdbc@postgresql.org" Subject: Fail-over PG server in connection string - syntax ? Thread-Topic: Fail-over PG server in connection string - syntax ? Thread-Index: Ac6G76dI4Qa1mOyLROKPn0M8JS/6mA== Date: Mon, 22 Jul 2013 15:35:45 +0000 Message-ID: <4da286cd15324df59679fa18960e58d3@Electra.virte.intra> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [192.168.10.26] Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=SHA1; boundary="----=_NextPart_000_000D_01CE8701.E4D9A930" MIME-Version: 1.0 X-Pg-Spam-Score: 1.9 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org ------=_NextPart_000_000D_01CE8701.E4D9A930 Content-Type: multipart/alternative; boundary="----=_NextPart_001_000E_01CE8701.E4D9A930" ------=_NextPart_001_000E_01CE8701.E4D9A930 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi all. We have 2 datacenters in diferent locations with public IP addresses each from different subnets. We would like to use Posgtres JDBC driver fail-over capability to switch over java client to secondary datacenter if the first one is unavailable. We need only basic functionality. We cannot use pgpool-II or something similar at the server side because all these type of softwares use one virtual IP address which in many cases is from one subnet. There should be fail-over capability available in the JDBC version 9.2-1000 according to changelog: http://jdbc.postgresql.org/changes.html#version_9.2-1000 The documentation doesn't mention how to build fail-over connection string at all. I've found in following mailing list thread mentioning the structure of the connection string: http://postgresql.1045698.n5.nabble.com/Re-Failover-Datasource-td4496411.htm l#a5736270 I tried fail-over by using the version 9.2-1002 in the following example. I tried to build easy test java script according to this site: http://www.dotnetfunda.com/Blogs/Niladri.Biswas/3743/connect-to-postgresql-f rom-java-using-jdbc-driver The java file then looks like this. import java.sql.*; public class JavaPostgreSQLConnectivityTest { public static void main(String[] args) { String connectionString = "jdbc:postgresql://pgsqldc1:5432/test,pgsqldc2:5432/test"; String userName = "postgres"; String password = "postgres"; try { Class.forName("org.postgresql.Driver"); //specify the JDBC driver for PostgreSQL Connection conn = DriverManager.getConnection(connectionString, userName, password); System.out.println("Connection properly established"); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM mytable ORDER BY created DESC LIMIT 5"); while (rs.next()) { System.out.print("Column 1 returned "); System.out.println(rs.getString(1)); } rs.close(); st.close(); } catch (Exception e) { e.printStackTrace(); } } } When I ran the java compiled class I got this. D:\temp\Scripts>java -cp postgresql-9.2-1003.jdbc4.jar; JavaPostgreSQLConnectivityTest org.postgresql.util.PSQLException: FATAL: database "test,pgsqldc2:5432/test" does not exist at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionF actoryImpl.java:572) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFa ctoryImpl.java:177) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java: 64) at org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection. java:136) at org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection. java:29) at org.postgresql.jdbc3g.AbstractJdbc3gConnection.(AbstractJdbc3gConnecti on.java:21) at org.postgresql.jdbc4.AbstractJdbc4Connection.(AbstractJdbc4Connection. java:31) at org.postgresql.jdbc4.Jdbc4Connection.(Jdbc4Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at JavaPostgreSQLConnectivityTest.main(JavaPostgreSQLConnectivityTest.java:15) What is the correct syntax for building connection string? Should the fail-over within postgres-jdbc driver work? Best regards, Michal Mistina ------=_NextPart_001_000E_01CE8701.E4D9A930 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi all.

We have 2 = datacenters in diferent locations with public IP addresses each from = different subnets. We would like to use Posgtres JDBC driver fail-over = capability to switch over java client to secondary datacenter if the = first one is unavailable. We need only basic functionality. We cannot = use pgpool-II or something similar at the server side because all these = type of softwares use one virtual IP address which in many cases is from = one subnet.

 

There should be fail-over capability available in the = JDBC version 9.2-1000 according to changelog: = http://jdbc.postgresql.org/changes.html#version_9.2-1000

 

The = documentation doesn’t mention how to build fail-over connection = string at all. I’ve found in following mailing list thread = mentioning the structure of the connection string:

http://postgresql.1045698.n5.nabble.com/Re-Failove= r-Datasource-td4496411.html#a5736270

 

I tried = fail-over by using the version 9.2-1002 in the following = example.

 

I tried to build easy test java script according to = this site: http://www.dotnetfunda.com/Blogs/N= iladri.Biswas/3743/connect-to-postgresql-from-java-using-jdbc-driver<= o:p>

 

The java file then looks like = this…

 

import java.sql.*;

 

public class = JavaPostgreSQLConnectivityTest

{

    public static void main(String[] = args)

    {

         &= nbsp;      String connectionString =3D = "jdbc:postgresql://pgsqldc1:5432/test,pgsqldc2:5432/test";=

         &= nbsp;      String userName =3D = "postgres";

         &= nbsp;      String password =3D = "postgres";

 

=             &= nbsp;  try

        = {

         &= nbsp;  Class.forName("org.postgresql.Driver"); //specify = the JDBC driver for PostgreSQL

 

         &= nbsp;  Connection conn =3D = DriverManager.getConnection(connectionString, userName, = password);

 

         &= nbsp;  System.out.println("Connection properly = established");

         &= nbsp;  Statement st =3D conn.createStatement();

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;  ResultSet rs =3D st.executeQuery("SELECT * FROM mytable = ORDER BY created DESC LIMIT 5");

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;            = ;      while (rs.next()) {

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;            = ;            =           = System.out.print("Column 1 returned ");

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;            = ;            =           = System.out.println(rs.getString(1));

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;            = ;      }

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;  rs.close();

         &= nbsp;           &n= bsp;           &nb= sp;           &nbs= p;  st.close();

        = }

        catch = (Exception e)

        = {

         &= nbsp;  e.printStackTrace();

        = }

        =

    }

}

 

When I ran = the java compiled class I got this…

 

D:\temp\Scripts>java -cp = postgresql-9.2-1003.jdbc4.jar; = JavaPostgreSQLConnectivityTest

org.postgresql.util.PSQLException: = FATAL: database "test,pgsqldc2:5432/test" does not = exist

      =   at = org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(Connecti= onFactoryImpl.java:572)

      =   at = org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Connectio= nFactoryImpl.java:177)

      =   at = org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.ja= va:64)

      =   at = org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Co= nnection.java:136)

      =   at = org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Co= nnection.java:29)

      =   at = org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3= gConnection.java:21)

      =   at = org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Co= nnection.java:31)

      =   at = org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24= )

      =   at = org.postgresql.Driver.makeConnection(Driver.java:393)

      =   at = org.postgresql.Driver.connect(Driver.java:267)

      =   at java.sql.DriverManager.getConnection(Unknown = Source)

      =   at java.sql.DriverManager.getConnection(Unknown = Source)

      =   at = JavaPostgreSQLConnectivityTest.main(JavaPostgreSQLConnectivityTest.java:1= 5)

 

What is the = correct syntax for building connection string? Should the fail-over = within postgres-jdbc driver work?

 

Best = regards,

Michal = Mistina

 

------=_NextPart_001_000E_01CE8701.E4D9A930-- ------=_NextPart_000_000D_01CE8701.E4D9A930 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIIVDCCBA8w ggL3oAMCAQICAQEwDQYJKoZI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