Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Postgres Heroku DB through Intellij IDEA

I've been trying to connect to my postgres DB all day. I can do it through pgAdmin, but I can't connect through mySQLWorkbench to migrate it and also can't connect through Intellij IDEA. We'll start w/Intellij though...

So, when I try to connect through IntelliJ, I get this...

Connection to Sinthetics failed
java.sql.SQLException: SSL error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I take this to mean that I need a certificate, since I'm using SSL (because it's a postgres/heroku). So, I run my handy InstallCert like so...

java InstallCert ec2-54-243-235-169.compute-1.amazonaws.com:5432

And get this back:

Loading KeyStore /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/security/cacerts...
Opening connection to ec2-54-243-235-169.compute-1.amazonaws.com:5432...
Starting SSL handshake...

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:953)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at InstallCert.main(InstallCert.java:87)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(InputRecord.java:482)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
    ... 4 more
Could not obtain server certificate chain

So why can't I get a cert for this, but it connects with no problem with pgAdmin!? Does anybody have a clue at all?

like image 302
darkMatter Avatar asked Jun 04 '15 03:06

darkMatter


3 Answers

Create DB with Host, Port, Database, User, Password from data.heroku.com

Go to Advanced tab and put :

  • ssl: true
  • sslfactory: org.postgresql.ssl.NonValidatingFactory

If you get error like this:

Connection to xxx.amazonaws.com failed. [08006] The hostname xxx.amazonaws.com could not be verified by hostnameverifier PgjdbcHostnameVerifier

Just put this value to advanced tab too:

  • sslmode: verify-ca
like image 23
Arthur Kupriyanov Avatar answered Nov 04 '22 05:11

Arthur Kupriyanov


To add new connection to your PostreSQL on Heroku in Intellij Idea you need to:

  1. Database Tool Window / New / Data Source / PostreSQL

  2. Put Host, Port, Database, User, Password that you find on https://postgres.heroku.com/databases

  3. Go to Advanced tab and put:

    • ssl: true
    • sslmode: verify-ca
    • sslfactory: org.postgresql.ssl.NonValidatingFactory
  4. Profit.

like image 69
gs_vlad Avatar answered Nov 04 '22 06:11

gs_vlad


I get the same issue, downgrading to a minor version of Postgre Driver worked for me.

PostgreDriverSettings:

PostgreDriverSettings

like image 1
Alexandre Lionne Avatar answered Nov 04 '22 06:11

Alexandre Lionne