首批通过分布式安全可靠测评,为关键业务系统打造
批量执行 SQL 报错
更新时间:2023-12-07 03:16
在 OceanBase 数据库中,在应用端批量执行 SQL 语句时报错。本文介绍出现该问题的原因和解决方法。
适用版本
OceanBase 数据库 V2.X 及以后的版本
问题现象
OceanBase 数据库升级到 V2.X 版本之后,在应用端批量执行 SQL 语句时报错,错误信息如下。
20200819 10:xx:xx.712 [Thread-40] [] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 08S01
20200819 10:xx:xx.712 [Thread-40] [] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Communications link failure
The last packet successfully received from the server was 195,898 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
20200819 10:xx:xx.718 [Thread-40] [] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: null
20200819 10:xx:xx.719 [Thread-40] [] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - connection holder is null
20200819 10:xx:xx.719 [Thread-40] [] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: null
20200819 10:xx:xx.719 [Thread-40] [] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - connection holder is null
20200819 10:xx:xx.720 [Thread-40] [] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: null
20200819 10:xx:xx.720 [Thread-40] [] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - connection holder is null
可能原因
获取故障时间段的 observer.log,有效信息如下。
[2020-08-19 10:54:00.025000] WARN [SQL.SESSION] is_timeout (ob_basic_session_info.cpp:4256) [49][4][Y0-0000000000000000] [lt=15] ob_trx_idle_timeout happen(sessid=3221544745, curr_trans_last_stmt_end_time=1597805460806759, ob_trx_idle_timeout=120000000)
[2020-08-19 10:54:00.025021] INFO [SQL] ob_sql_session_mgr.cpp:577 [49][4][Y0-0000000000000000] [lt=17] session is timeout, kill this session(key.version_=0, key.sessid_=3221544745)
[2020-08-19 10:54:00.025153] INFO [SQL] ob_sql_session_mgr.cpp:487 [49][4][Y0-0000000000000000] [lt=4] kill session successfully(proxy="xxx.xxx.xxx.xxx", peer="xxx.xxx.xxx.xxx:59636", real_client_ip=xxx.xxx.xxx.xxx, sessid=3221544745, proxy_sessid=5046, trans_id={hash:10216819819253321717, inc:11503543, addr:"xxx.xxx.xxx.xxx:2882", t:1597805460806759}, is_trans_end=true, query_str=BEGIN)
说明连接被 observer 进程停止,通过查看 curr_trans_last_stmt_end_time=1597805460806759,转换为事务发起的时间。
obclient> SELECT usec_to_time(1597805460806759);
+--------------------------------+
| usec_to_time(1597805460806759) |
+--------------------------------+
| 2020-08-19 10:51:00.806759 |
+--------------------------------+
1 row in set (0.03 sec)
查看 OBProxy 日志,根据信息判断是由于触发了 ob_trx_idle_timeout 设置的超时时间,如下图所示。

OceanBase 数据库自 V2.0 起,引入 ob_trx_idle_timeout 参数控制显示事务的空闲超时,当应用开启显示事务后即进入空闲等待逻辑。后台进程会定时扫描事务中各语句的间隔,若超过空闲设置,连接将被断开。
ob_trx_idle_timeout 默认为 120 秒。有关该参数的更多信息,参见《OceanBase 数据库 参考指南》中的 系统配置项 章节。
解决方式
结合实际业务调整 ob_trx_idle_timeout 参数的大小。例如:
obclient> SET GLOBAL ob_trx_idle_timeout = 200000000;