我知道这是一个重复的问题.但我找不到相同的解决方案.我已经在Amazon EC2云中托管了我的应用程序.我正在使用postgresql.我收到异常org.postgresql.util.PSQLException:发送到后端时发生I / O错误.在Amazon cloud运...
我知道这是一个重复的问题.但我找不到相同的解决方案.
我已经在Amazon EC2云中托管了我的应用程序.
我正在使用postgresql.
我收到异常org.postgresql.util.PSQLException:发送到后端时发生I / O错误.在Amazon cloud运行我的应用程序.
详细的堆栈跟踪是:
org.postgresql.util.PSQLException: An I/O error occured while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:281)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:331)
at com.spy2k3.core.business.processor.ProcessorImpl.executeUpdate(ProcessorImpl.java:237)
at com.spy2k3.core.business.object.BusinessObject.executeUpdate(BusinessObject.java:54)
at com.spy2k3.core.business.object.LoginObject.deleteSession(LoginObject.java:127)
at com.spy2k3.core.business.processor.LoginProcessor.userValidation(LoginProcessor.java:79)
at com.spy2k3.core.business.processor.LoginProcessor.execute(LoginProcessor.java:30)
at com.spy2k3.core.business.processor.ProcessorImpl.process(ProcessorImpl.java:73)
at com.spy2k3.core.handler.request.RequestHandler.doService(RequestHandler.java:90)
at com.spy2k3.core.handler.AbstractHandler.doPost(AbstractHandler.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:71)
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:269)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1700)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
... 37 more
测试:
1.我通过PgAdmin从本地系统连接我的远程postgresql服务器,我可以连接并执行查询.
2.我通过putty连接到我的远程服务器,并且可以成功执行查询.
示例:
06001
3.当我通过jdbc从我的应用程序连接我的远程数据库时,它已成功连接,但是在那里执行查询需要花费太多时间.
你能建议任何解决方案来找出这个时间延迟吗?
更新:
在深入研究问题期间,我发现延迟只发生在DELETE,UPDATE等特定查询中. INSERT,SELECT等查询执行正常.
DELETE和UPDATEqueries的特性是什么都不返回.
所以实际问题是查询客户端(假设psql)正在等待数据库服务器响应,但对于这些查询服务器什么都不返回.所以客户端一直等待,超时后抛出异常.
但我无法找到改变的地方来解决这个问题.
解决方法:
问题在于postgresql.conf中的synchronous_standby_names参数.
在我的postgresql.conf中,它是synchronous_standby_names =’*’.
当我注释掉这一行时,我能够执行所有查询.
从PostgreSQL documentation:
synchronous_standby_names (string) : At any one time there will be at most one
active synchronous standby; transactions waiting for commit will be
allowed to proceed after this standby server confirms receipt of their
data.. . .
If no synchronous standby names are specified here, then synchronous
replication is not enabled and transaction commits will not wait for
replication.
所以实际问题是:查询客户端(假设psql)正在等待数据库服务器响应,但对于这些查询,服务器返回任何内容,因为启用了同步复制.所以客户端一直在等待,并在超时后抛出异常.
本文标题为:java – PostgreSQL异常:org.postgresql.util.PSQLException:发送到后端时发生I / O错误
基础教程推荐
- JSP验证码动态生成方法 2023-08-03
- 使用工具类-java精确到小数点后6位 2023-06-24
- 一篇文章带你搞懂Java线程池实现原理 2023-07-01
- java – H2数据库:如何使用加密保护,而不暴露文件加密密钥 2023-11-09
- jsp获得本地及serverIP的简单方法 2023-08-02
- JSP中的FORM表单中只有一个input文本时,按回车键将会自动提交表单 2023-08-01
- java模拟实现银行ATM机操作 2022-11-16
- Android通过蓝牙发送数据到Windows PC电脑:Java实现 2023-09-01
- jsp网页实现贪吃蛇小游戏 2023-07-30
- Spring框架中 @Autowired 和 @Resource 注解的区别 2023-08-01