HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Trying to connect a PostgreSQL database to Eclipse

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlconnecteclipsetryingdatabase

Problem

I have a Postgres (version 9.2) database running on a Centos 7 machine, and I'm trying to connect to it from Eclipse Oxygen on a Windows 10 machine using the Data Source Explorer.

When I put in all the information on the Connection Details screen in Eclipse and hit "Test Connection", I get this error:

```
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:250)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.connect(Driver.java:256)
at org.eclipse.datatools.enablement.internal.postgresql.PostgreSQLJDBCConnection.createConnection(PostgreSQLJDBCConnection.java:87)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.enablement.internal.postgresql.PostgreSQLJDBCConnection.(PostgreSQLJDBCConnection.java:47)
at org.eclipse.datatools.enablement.internal.postgresql.PostgreSQLConnectionFactory.createConnection(PostgreSQLConnectionFactory.java:51)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSock

Solution

This line shows the problem:

Caused by: java.net.SocketTimeoutException: connect timed out


As a rule of thumb, typically in Java stacktraces, the first "Caused by" (printed last) is what you want.

Your Win10 can't connect to the postgresql on your CentOS. PostgreSQL uses typically the TCP port 5432.

It gets a connection timeout error, which means your win10 absolutely doesn't get an answer. Nothing. If your postgresql wouldn't allow the connection, or if your postgresql wouldn't listen on your tcp port 5432, you had got "authentication error" or "connection refused" error.

But your win10 doesn't get anything, not even an error. As if your server wouldn't even exist.

You can check the availability of your postgresql with a

telnet your.centos.ip 5432


command.

The most probably cause of your problem is that the default firewall configuration of your centos simply filters out the 5432 port. Enable it.

The second most probable cause is that you simply typed in a false IP.

If you solved that problem, then

  • your telnet command won't hang up



  • your java software will connect, or at least it will have a different error (authentication error or connection refused are the most likely).



Making postgresql listening on the network requires also some different settings, beside your firewall configuration:

  • You have to set up your postgresql to listen on all IP addresses, not only on localhost. This can be done with a listen_addresses line of your postgresql.conf.



  • You have to set up some authentication (md5 password is the most likely) in the pg_hba.conf.



First connect your postgresql with some client, for example with pgadmin or with the command line psql tool (it comes also with cygwin). After it works, only then play to connect it from Java.

Code Snippets

Caused by: java.net.SocketTimeoutException: connect timed out
telnet your.centos.ip 5432

Context

StackExchange Database Administrators Q#212450, answer score: 4

Revisions (0)

No revisions yet.