Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.; An I/O error occurred while sending to the backend.; nested exception is org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
Caused by: java.net.SocketTimeoutException: Read timed out;
最近在做一个复杂查询,数据量比较大,需要二十多秒才能返回得结果,提交了请求之后还没等结果吐出来就报错了,发现是因为没有添加超时配置,所以在查询又或者读取的时候超时了,我这里是读取的时候超时了,既然超时了直接把超时时间延长就好了,我用的是druid(德鲁伊)
在数据库url补上两个参数 socketTimeout=300000&loginTimeout=60000
spring:
datasource:
url: jdbc:postgresql://localhost:3306/yourdb?socketTimeout=300000&loginTimeout=60000
或者
connection-timeout: 60000 # 建立连接超时:60秒
socket-timeout: 300000 # Socket读取超时:5分钟
query-timeout: 180000 # 查询执行超时:3分钟
