I have two virtual machines where one is hosting postgres DB and another application that is connecting to database. I have tried multiple configuration ways, but every time connecting I'm connecting via JDBC I get:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
at org.postgresql.Driver.makeConnection(Driver.java:465)
at org.postgresql.Driver.connect(Driver.java:264)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
at java.base/java.net.Socket.connect(Unknown Source)
at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
at org.postgresql.core.PGStream.<init>(PGStream.java:95)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
For now in my pg_hba.conf file I have configured application host with:
host my_db user 192.168.14.147/32 password (tried md5 and even trust, same result)
I have also checked postgresql.conf and I have
listen_addresses = '*'
I have reloaded conf in db with:
SELECT pg_reload_conf();
My postgresql server is working on host 192.168.44.38. Before I've added pg_hba.conf configuration I was getting error about no entry in this file and I also tried to connect to DB via pgAdmin and it works, so my config should be okay.
My jdbc connection method:
try {
String postgresConnectionUrl = "jdbc:postgresql://192.168.44.38:5432/my_db";
Connection connection = DriverManager.getConnection(postgresConnectionUrl, "user", "my_pass");
return connection;
} catch (SQLException sqlException) {
log.error("Error connecting. ", sqlException);
return null;
}
I've found nothing in postgres logs, also my user account has no limited connections and isn't even used.