Postgres 11,如果管道不活动,则接收到损坏的管道

问题描述 投票:0回答:1

Spring应用程序偶尔会记录破损的管道。为了处理过时的连接问题,应用程序已经在使用-

testWhileIdle = truevalidationQuery = SELECT 1

堆栈跟踪-

    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:333)
            at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
            at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
            at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
            at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
            at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
            at com.sun.proxy.$Proxy137.executeQuery(Unknown Source)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
            ... 133 more
    Caused by: java.net.SocketException: Connection reset
            at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
            at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
            at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
            at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
            at org.postgresql.core.PGStream.flush(PGStream.java:514)
            at org.postgresql.core.v3.QueryExecutorImpl.sendSync(QueryExecutorImpl.java:1363)
            at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:304)
            ... 143 more
     Caused by java.net.SocketException: Broken pipe (Write failed)

一种模糊的感觉,如果应用程序在一段时间内保持不活动状态,则可能会导致连接后端的问题,反之亦然。但是由于无法在本地重现此问题,因此很难指出。

postgresql spring-boot connection-pooling
1个回答
0
投票

您可以尝试将空闲连接的超时设置为更高。

idle_in_transaction_session_timeout = 30000

在postgresql.conf中

但是您的错误对我来说很奇怪。我可能会检查您是否也无法建立许多连接。

在spring-boot端,您可以尝试添加以下属性:

spring.datasource.test-on-borrow=true
   spring.datasource.validation-query=SELECT 1
   spring.datasource.validation-interval=30000

您可以尝试缩短验证间隔。我将其设置为默认值

希望有帮助

© www.soinside.com 2019 - 2024. All rights reserved.