Reputation: 725
I am trying to access a table from PostgreSQL present in other machine. I am getting the following error.
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:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.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)
I have configured my ip in pg_hba.conf file as well but the same error exists. What could be the solution for it?
Upvotes: 2
Views: 10327
Reputation: 31
I am new to PostgreSql but i also had a same problem so many times, at last i found solution.
The problem was with firewall blocking port (for Ex : 5432) , once this was granted access through the firewall, i was able to connect to the database server.
You have to add only port which you are using in postgreSql to Firewall.
after this my postgreSql works Fine with Jdbc.
Upvotes: 1
Reputation: 15985
I has same problem. I added following entry in pg_hba.conf and worked. Make sure you restart postgres after changin configuration file
host all all 0.0.0.0/0 md5
Upvotes: 0
Reputation: 126971
What is the setting for "listen_addresses" in postgresql.conf?
SHOW listen_addresses;
And did you reload the configurationfiles after the changes in pg_hba.conf and postgresql.conf?
SELECT pg_reload_conf();
Upvotes: 0
Reputation: 753455
Can you telnet to the IP address and port number where you think PostgreSQL is listening?
If not, the trouble is that the postmaster is not running, or that you have something screwball in your network - firewalls blocking access to the port, or can't locate the host or whatever.
If you can get to the postmaster via telnet, then it may be that you've given the wrong credentials or something - but the error suggests that your client code is unable to find the remote PostgreSQL. More likely, though, the configuration being used by the Java code is not the same as the one you successfully demonstrated as working with telnet.
Upvotes: 3