数据库Communications link failure

隔一段时间会报一次错
查了下好像是客户端连接还开着,但是数据库服务器主动关闭了?
那如何修改呢?求大佬看看
数据库使用OceanBase的Oracle模式
Druid+MyBatis
报错如下:

### Error querying database.  Cause: com.alipay.oceanbase.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,076,862 milliseconds ago.  The last packet sent successfully to the server was 124 milliseconds ago.

### Cause: com.alipay.oceanbase.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,076,862 milliseconds ago.  The last packet sent successfully to the server was 124 milliseconds ago.
; SQL []; Communications link failure

The last packet successfully received from the server was 1,076,862 milliseconds ago.  The last packet sent successfully to the server was 124 milliseconds ago.; nested exception is com.alipay.oceanbase.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,076,862 milliseconds ago.  The last packet sent successfully to the server was 124 milliseconds ago.
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy169.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy177.selectByExample(Unknown Source)

连接参数:

spring.datasource.ob.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.ob.driverClassName=com.alipay.oceanbase.jdbc.Driver
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
spring.datasource.ob.initialSize=5
spring.datasource.ob.minIdle=5
spring.datasource.ob.maxActive=20
# 配置获取连接等待超时的时间
spring.datasource.ob.maxWait=60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.ob.timeBetweenEvictionRunsMillis=60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.ob.minEvictableIdleTimeMillis=300000
spring.datasource.ob.validationInterval=5000
spring.datasource.ob.validationQuery=SELECT 1 FROM DUAL
spring.datasource.ob.testWhileIdle=true
spring.datasource.ob.testOnBorrow=false
spring.datasource.ob.testOnReturn=false
# 打开PSCache,并且指定每个连接上PSCache的大小
spring.datasource.ob.poolPreparedStatements=true
spring.datasource.ob.maxPoolPreparedStatementPerConnectionSize=20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.ob.filters=stat,wall,log4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.ob.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

url已经添加autoReconnect=true,且testOnBorrow,testOnReturn均改为true仍会报错

数据库属性:

autocommit    ON
connect_timeout    60
interactive_timeout    31536000
last_insert_id    0
max_allowed_packet    4194304
ob_compatibility_mode    ORACLE
ob_max_parallel_degree    32
ob_query_timeout    36000000000
ob_read_consistency    STRONG
ob_route_policy    READONLY_ZONE_FIRST
ob_trx_timeout    36000000000
tx_isolation    READ-COMMITTED
wait_timeout    31536000
阅读 3.6k
1 个回答

程序认为这个连接是正常连接可用,但实际上Mysql本身已经把这个连接标记为timeout了。试着在你的url连接属性中加入 autoReconnect=true属性。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题