org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

  • org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
    • 异常堆栈信息
    • 参考
    • 问题、解决办法及建议

org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

异常堆栈信息

org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:327) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:117) ~[postgresql-42.1.4.jar:42.1.4]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2830) ~[druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeQuery(FilterEventAdapter.java:465) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2827) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.wall.WallFilter.preparedStatement_executeQuery(WallFilter.java:640) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2827) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeQuery(FilterEventAdapter.java:465) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2827) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.executeQuery(PreparedStatementProxyImpl.java:181) [druid-1.1.9.jar:1.1.9]
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:228) [druid-1.1.9.jar:1.1.9]
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:71) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.getResultSet(Loader.java:2123) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1911) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1887) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.doQuery(Loader.java:932) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.doList(Loader.java:2615) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.doList(Loader.java:2598) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.Loader.list(Loader.java:2425) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:379) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1488) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.uniqueResult(AbstractProducedQuery.java:1457) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at com.paic.core.hibernate.GenericDao$3.doInHibernate(GenericDao.java:154) [polaris-common-0.0.1-SNAPSHOT.jar:?]
	at com.paic.core.hibernate.GenericDao$3.doInHibernate(GenericDao.java:120) [polaris-common-0.0.1-SNAPSHOT.jar:?]
	at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:383) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:349) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at com.paic.core.hibernate.GenericDao.count(GenericDao.java:120) [polaris-common-0.0.1-SNAPSHOT.jar:?]
	at com.paic.core.hibernate.GenericDao.count(GenericDao.java:114) [polaris-common-0.0.1-SNAPSHOT.jar:?]
	at com.paic.biz.funcLib.FuncLibService.funcLibList(FuncLibService.java:107) [polaris-biz-0.0.1-SNAPSHOT.jar:?]
	at com.paic.biz.funcLib.FuncLibService$$FastClassBySpringCGLIB$$6bf19ab2.invoke(<generated>) [polaris-biz-0.0.1-SNAPSHOT.jar:?]
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685) [spring-aop-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at com.paic.biz.funcLib.FuncLibService$$EnhancerBySpringCGLIB$$cf96c490.funcLibList(<generated>) [polaris-biz-0.0.1-SNAPSHOT.jar:?]
	at com.paic.web.controller.api.FuncLibDataController.funcLibList(FuncLibDataController.java:40) [polaris-studio-rest-0.0.1-SNAPSHOT.jar:?]
	at sun.reflect.GeneratedMethodAccessor995.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_66]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) [servlet-api.jar:?]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) [spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [servlet-api.jar:?]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:8.5.16]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.16]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.5.16]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.16]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.16]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.16]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.16]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [catalina.jar:8.5.16]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:8.5.16]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [catalina.jar:8.5.16]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:8.5.16]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [catalina.jar:8.5.16]
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) [catalina.jar:8.5.16]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:8.5.16]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [catalina.jar:8.5.16]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-coyote.jar:8.5.16]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:8.5.16]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-coyote.jar:8.5.16]
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2298) [tomcat-coyote.jar:8.5.16]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:8.5.16]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_66]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_66]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.5.16]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_66]
Caused by: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 41675
	at org.postgresql.core.PGStream.sendInteger2(PGStream.java:219) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1467) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1778) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1354) ~[postgresql-42.1.4.jar:42.1.4]
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:292) ~[postgresql-42.1.4.jar:42.1.4]
	... 84 more
2018-10-25 11:06:02 [ ERROR ] [ com.alibaba.druid.pool.DruidDataSource ] discard connection

参考

PostgreSQL and Hibernate java.io.IOException: Tried to send an out-of-range integer as a 2-byte value

问题、解决办法及建议

  • 对postgresql的 select xxx from table_name where yyy in (1,2,…,n) 查询的()中的参数个数(4w+)超出允许的最大范围(32767)(有的数据库引擎对sql长度也有限制)
  • 本次遇到这个问题,最终通过新增一个表连接查询,来减小查询参数的个数。最终解决问题。
  • 开发时,应该尽量避免这种查询,如果出现这种查询,应该首先考虑是不是设计有问题,找出替代方案。

你可能感兴趣的:(database)