【问题标题】:Connecting to Postgres Heroku DB through Intellij IDEA通过 Intellij IDEA 连接 Postgres Heroku DB
【发布时间】:2022-01-28 02:40:59
【问题描述】:

我整天都在尝试连接到我的 postgres 数据库。我可以通过 pgAdmin 来完成,但我无法通过 mySQLWorkbench 连接来迁移它,也无法通过 Intellij IDEA 连接。不过,我们将从 Intellij 开始...

所以,当我尝试通过 IntelliJ 连接时,我得到了这个...

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

我认为这意味着我需要一个证书,因为我使用的是 SSL(因为它是一个 postgres/heroku)。所以,我像这样运行我方便的 InstallCert...

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

然后把它拿回来:

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

那么为什么我不能为此获得证书,但它与 pgAdmin 连接没有问题!?有人有线索吗?

【问题讨论】:

    标签: postgresql ssl heroku intellij-idea


    【解决方案1】:

    要在 Intellij Idea 中为 Heroku 上的 PostreSQL 添加新连接,您需要:

    1. 数据库工具窗口/新建/数据源/PostreSQL

    2. 将您在https://postgres.heroku.com/databases找到的主机、端口、数据库、用户、密码输入

    3. 转到高级选项卡并输入:

      • ssl:真
      • sslmode:验证-ca
      • sslfactory:org.postgresql.ssl.NonValidatingFactory
    4. 利润。

    【讨论】:

    • 那对我不起作用,我收到一个错误:java.lang.ClassNotFoundException: org.postgresql.ssl.NonValidatingFactory [2017-01-20 19:52:20] 在 java.net .URLClassLoader.findClass(URLClassLoader.java:381) [2017-01-20 19:52:20] 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) [2017-01-20 19:52:20]在...
    【解决方案2】:

    从 data.heroku.com 创建包含主机、端口、数据库、用户、密码的数据库

    转到高级选项卡并输入:

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

    如果你得到这样的错误:

    与 xxx.amazonaws.com 的连接失败。 [08006] 主机名 xxx.amazonaws.com 无法通过 hostnameverifier 验证 PgjdbcHostnameVerifier

    只需将此值也放入高级选项卡:

    • sslmode:验证-ca

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,降级到 Postgre Driver 的次要版本对我有用。

      PostgreDriver设置:

      【讨论】:

      • 从 42.2.5 到 42.2:DBMS:PostgreSQL(版本 11.4);区分大小写:plain=lower,delimited=exact;驱动:PostgreSQL JDBC驱动(ver. 42.2.2, JDBC4.2);平:39 毫秒
      【解决方案4】:

      为了连接,我只是这样做了:

      1. 在设置中转到 Heroku 上的应用
      2. 找到环境变量DATABASE_URL
      3. 将其复制并粘贴到您计算机上的某个位置

      DATABASE_URL 的值是这样的:

      postgres://this-is-theuser:this-is-a-very-long-long-long-password@ec2-34-756-294-13.eu-west-1.compute.amazonaws.com:5432/this-is-the-database
      

      请勿在 PHPSTORM 的 Url: 字段中直接复制并粘贴此值

      相反,手动将每个值放入表单中,让 PHPStorm 自己构建 URL 并尝试连接。它应该可以工作。

      【讨论】:

        猜你喜欢
        • 2021-11-23
        • 1970-01-01
        • 2019-08-31
        • 2022-12-18
        • 2023-04-06
        • 2016-08-14
        • 2019-07-15
        • 2014-10-08
        • 1970-01-01
        相关资源
        最近更新 更多