【问题标题】:Postgresql connecting issue with pgjdbc-ngPostgresql 与 pgjdbc-ng 的连接问题
【发布时间】:2022-12-23 12:22:14
【问题描述】:

我正在尝试将 postgresql 与 pgjdbc-ng(0.8.9) 连接起来用于异步侦听器。开发时一切正常,但我在 SIT 环境中连接超时。
SIT 中有一个 postgresql 13 服务器,强制客户端使用 ssl 连接,仅使用 tls 1.3。
这是代码:

@Bean
public PGConnection getPGConnection() throws SQLException {
    var connectionString = String
        .format("jdbc:pgsql://%s/%s?ssl.mode=require", host, database);
    return DriverManager
            .getConnection(connectionString, user, password)
            .unwrap(PGConnection.class);
}

这是堆栈跟踪打印出来的:

Cause by: java.io.IOException: Timeout starting connection
    at com.impossibl.postgres.protocol.v30.ServerConnectionFactory.startup
    ...

这让我感到困惑,因为只有来自上面代码的连接才会出现超时错误。Spring Data JPA(PostgreSQL JDBC Driver) 的其他连接在同一时间在同一个应用程序中是完全正确的。最糟糕的是我无法在我的环境中重现。
起初我以为这是关于 tls 协议版本,因为应用程序需要在 openssl 版本为 1.0.1 的机器上工作(不支持 tls 1.3)。但它看不到,因为其他连接正常。
我知道它没有被 postgres 用户的连接限制拒绝,因为它抛出不同的异常。而且我尝试使用不同的方式来获得连接,例如:

var dataSource = new PGDataSource();
dataSource.setUrl("jdbc:pgsql://host/dbname");
dataSource.setUser(user);
dataSource.setPassword(password);  
dataSource.setSslMode(SSLMode.Require.name());
var conn = dataSource.getConnection().unwrap(PGConnection.class);

它变成了相同的结果,在开发中工作并在 SIT 环境中失败。


有没有人有类似的经历?
或者请告诉我我应该向 DBA pg_hba.conf 或其他人查询什么?
谢谢你。

【问题讨论】:

  • 您是否尝试过使用 psql 在 SIT 环境中连接到启用 SSL 的 postgres 服务器?另外,你在使用 Docker 吗? jdbc.postgresql.org/documentation/80/ssl.html
  • @nulldroid 感谢您的评论。我无法连接 psql,因为 psql 的版本太低,无法支持 tls 1.3。但我确定来自 PostgreSQL JDBC 驱动程序的其他连接启用了 SSL。不,SIT 中没有 Docker。

标签: java postgresql spring-boot pgjdbc-ng


【解决方案1】:

@Bernie.T,您找到问题的解决方案了吗?当我们将 PostgreSQL 13 迁移到 14 时,我们面临着同样的问题。任何指针将不胜感激!

【讨论】:

    猜你喜欢
    • 2016-12-03
    • 1970-01-01
    • 2021-11-18
    • 2011-04-10
    • 2011-07-28
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多