Thread: Prolem to acess PostgeSQL from other mechine

Prolem to acess PostgeSQL from other mechine

From
Arun R T
Date:

Hi

I have some problem to connect PostgeSQL server from client mechine, error and code is given below. I am using Windows 7 OS

Code

public static void main(String[] args) {
       
        try {
            System.out.println("Connecting..................");
            Class.forName("org.postgresql.Driver").newInstance();
            connection = DriverManager.getConnection("jdbc:postgresql://10.10.10.101:6060/mydb", "postgres", "welcome");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Error

org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:123)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:28)
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:20)
    at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
    at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:22)
    at org.postgresql.Driver.makeConnection(Driver.java:391)
    at org.postgresql.Driver.connect(Driver.java:265)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.web.view.TestLogic.main(TestLogic.java:15)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.postgresql.core.PGStream.<init>(PGStream.java:60)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:74)
    ... 11 more

I am also sets

postgresql.conf

listen_addresses = '*'        # what IP address(es) to listen on;
                    # comma-separated list of addresses;


pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host     all     all     10.10.10.100/32     trust
# IPv6 local connections:
host     all     all     0.0.0.0/0     trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host     replication     postgres     127.0.0.1/32     md5
# host     replication     postgres     ::1/128     md5


Please give me a solution
 
Thanks & Regards
------------------------------------------------------------------------------------------------

Arun R T

Re: Prolem to acess PostgeSQL from other mechine

From
"David Johnston"
Date:

And the IP address of the machine you are trying to connect from is?

 

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Arun R T
Sent: Sunday, September 23, 2012 11:51 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Prolem to acess PostgeSQL from other mechine

 

 

Hi

 

I have some problem to connect PostgeSQL server from client mechine, error and code is given below. I am using Windows 7 OS

 

Code

 

public static void main(String[] args) {
       
        try {
            System.out.println("Connecting..................");
            Class.forName("org.postgresql.Driver").newInstance();
            connection = DriverManager.getConnection("jdbc:postgresql://10.10.10.101:6060/mydb", "postgres", "welcome");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

Error

 

org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:123)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:28)
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:20)
    at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
    at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:22)
    at org.postgresql.Driver.makeConnection(Driver.java:391)
    at org.postgresql.Driver.connect(Driver.java:265)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.web.view.TestLogic.main(TestLogic.java:15)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.postgresql.core.PGStream.<init>(PGStream.java:60)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:74)
    ... 11 more

 

I am also sets

 

postgresql.conf

 

listen_addresses = '*'        # what IP address(es) to listen on;
                    # comma-separated list of addresses;

 

 

pg_hba.conf

 

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host     all     all     10.10.10.100/32     trust
# IPv6 local connections:
host     all     all     0.0.0.0/0     trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host     replication     postgres     127.0.0.1/32     md5
# host     replication     postgres     ::1/128     md5

 

 

Please give me a solution

 

Thanks & Regards
------------------------------------------------------------------------------------------------

Arun R T

Re: Prolem to acess PostgeSQL from other mechine

From
Adrian Klaver
Date:
On 09/23/2012 08:50 PM, Arun R T wrote:
>
> Hi
>
> I have some problem to connect PostgeSQL server from client mechine,
> error and code is given below. I am using Windows 7 OS
>
> Code
>
> public static void main(String[] args) {
>
>          try {
>              System.out.println("Connecting..................");
>              Class.forName("org.postgresql.Driver").newInstance();
>              connection =
> DriverManager.getConnection("jdbc:postgresql://10.10.10.101:6060/mydb",
> "postgres", "welcome");
>          } catch (Exception e) {
>              e.printStackTrace();
>          }
>      }
>
> Error
>
> org.postgresql.util.PSQLException: Connection refused. Check that the
> hostname and port are correct and that the postmaster is accepting
> TCP/IP connections.
>      at
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
>      at
> org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
>      at
> org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:123)
>      at
> org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:28)
>      at
> org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:20)
>      at
> org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
>      at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:22)
>      at org.postgresql.Driver.makeConnection(Driver.java:391)
>      at org.postgresql.Driver.connect(Driver.java:265)
>      at java.sql.DriverManager.getConnection(Unknown Source)
>      at java.sql.DriverManager.getConnection(Unknown Source)
>      at com.web.view.TestLogic.main(TestLogic.java:15)
> Caused by: java.net.ConnectException: Connection timed out: connect
>      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
>      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
>      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
>      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
>      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
>      at java.net.PlainSocketImpl.connect(Unknown Source)
>      at java.net.SocksSocketImpl.connect(Unknown Source)
>      at java.net.Socket.connect(Unknown Source)
>      at java.net.Socket.connect(Unknown Source)
>      at java.net.Socket.<init>(Unknown Source)
>      at java.net.Socket.<init>(Unknown Source)
>      at org.postgresql.core.PGStream.<init>(PGStream.java:60)
>      at
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:74)
>      ... 11 more
>
> I am also sets
>
> postgresql.conf
>
> listen_addresses = '*'        # what IP address(es) to listen on;
>                      # comma-separated list of addresses;
>
>
> pg_hba.conf
>
> # TYPE  DATABASE        USER            ADDRESS                 METHOD
>
> # IPv4 local connections:
> host     all     all     10.10.10.100/32     trust
> # IPv6 local connections:
> host     all     all     0.0.0.0/0     trust
> # Allow replication connections from localhost, by a user with the
> # replication privilege.
> # host     replication     postgres     127.0.0.1/32     md5
> # host     replication     postgres     ::1/128     md5
>
>
> Please give me a solution

Did you restart the server after making the above changes?
A restart is needed  for the listen_address change to be seen.

Its unclear where the server is running. Is it running on Windows or is
the client running on Windows? In either case is there a firewall
between the two that could be preventing a connection?


> Thanks & Regards
> ------------------------------------------------------------------------------------------------
>
> *Arun R T*


--
Adrian Klaver
adrian.klaver@gmail.com


Re: Prolem to acess PostgeSQL from other mechine

From
Bosco Rama
Date:
On 09/23/12 20:50, Arun R T wrote:
>
> I have some problem to connect PostgeSQL server from client mechine
[snip]
> org.postgresql.util.PSQLException: Connection refused. Check that the hostname
> and port are correct and that the postmaster is accepting TCP/IP connections.

Given this ^^^ follow the recommendations:  Check that you are talking to the
correct host (10.10.10.101).  Then check that you have the right port number
(you had 6060 but you didn't mention that you had changed it from the default
which is usually 5432 for the first PG instance on a machine).  You indicated
that you had enabled listening for tcp on all addresses.  Did you (re)start
the server afterwards?

As a final act of desperation, make sure there is no intervening firewalls/routers
that may be rejecting it.

HTH

Bosco.