gpt4 book ai didi

java - 与 Postgres 数据库的连接丢失

转载 作者:行者123 更新时间:2023-11-29 12:53:08 26 4
gpt4 key购买 nike

在性能服务器上 - 负载相当大,我有一个奇怪的行为。从某一时刻开始,所有连接数据库开始说“连接已关闭”。

到目前为止唯一的提示是这个 IOException :

Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:314)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:116)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
... 73 more

Caused by: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 33001
at org.postgresql.core.PGStream.sendInteger2(PGStream.java:211)
at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1409)
at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1729)
at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1294)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:280)
... 83 more

但是我目前无法真正将其与某些业务场景联系起来。

有什么想法吗?

最佳答案

这是 PostgreSQL 驱动的限制,一个查询的最大参数个数是 32768。

您有一个超出该限制的查询 - 这样做时,驱动程序会出现关闭连接的不稳定行为。我在使用 Hibernate 和 PostgreSQL 的 JBoss 服务器上遇到过这种情况,连接关闭导致连接池状态非常困惑。

这个参数描述here ,在解析部分:“Int16 - 指定的参数数据类型的数量”。

解决方案是将长查询拆分为具有已知参数数量的较小查询。

关于java - 与 Postgres 数据库的连接丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49402978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com