首批通过分布式安全可靠测评,为关键业务系统打造
PL 嵌套调用 refcursor 报错 5930
更新时间:2026-05-29 08:46
问题现象
Oracle 租户下,执行嵌套调用 refcursor 的 PL 时( pl1 中 refcursor 被当作出参,pl2 调用 pl1 且 pl1 出参中的 refcursor 没有被驱动绑定),会导致 open_cursors 引用计数持续泄漏。
持续执行该类型 PL 时,查看
v$sysstat可发现open cursor数持续增长(断链接可恢复)。当
open_cursors数量超过限制时,则执行会报错 5930,报错日志如下。WARN [SQL.SESSION] add_cursor (ob_sql_session_info.cpp:1175)........maxium open cursors exceeded(ret=-5930, open_cursors_limit=50, .......)
问题 PL 示例如下。
-- pl1 中 SYS_REFCURSOR(即 refcursor) 为出参
create or replace procedure pl1(a out sys_refcursor) is
begin
open a for select 1 from dual;
end;
/
-- 该 PL 嵌套调用了 pl1
declare
a sys_refcursor;
begin
pl1(a);
close a;-- 即使 close 了,引用计数依然会泄漏
end;
/
关键诊断信息
触发条件
嵌套调用 refcursor 的 PL 时(pl1 中 refcursor 被当作出参,pl2 调用 pl1 且 pl1 出参中的 refcursor 没有被驱动绑定)。
事前巡检
pl1 中 refcursor 被当作出参。
pl2 调用 pl1,且 pl1 出参中的 refcursor 没有被驱动绑定。
事后诊断
报错日志信息:
WARN [SQL.SESSION] add_cursor (ob_sql_session_info.cpp:1175)........maxium open cursors exceeded(ret=-5930, open_cursors_limit=50, .......)
问题原因
refcursor被当作出参时会被定义为一个 session cursor, 占用open_cursors引用计数。PL 中的
refcursor在关闭时只释放了cursor内存,没有释放open_cursors引用计数。
问题的风险及影响
open_cursors 引用计数占用,长链接报错 5930。
影响版本
OceanBase 数据库 V2.2.77 GA(oceanbase-2.2.77-20210508211731)及之后版本、V3.1.2 GA(oceanbase-3.1.2-20210618150922)及之后版本、V3.2.3 GA(oceanbase-3.2.3.0-20220418212020)及之后版本、V3.2.4 GA(oceanbase-3.2.4.0-100000072022102819)及之后版本、V4.1.0 GA(oceanbase-4.1.0.0-100001122023040322)及之后版本。
解决方法及规避方式
kill执行这个 PL 的 session 解决 5930 问题。- 修改 PL,避免 PL 嵌套
refcursor作为出参的 PL。 - 升级到问题已修复版本,目前已修复的版本包含 OceanBase 数据库 V3.2.3 BP10(oceanbase-3.2.3.3-110000092023091219)、V3.2.4 BP6(oceanbase-3.2.4.6-106000062023110109)、V4.1.0 BP4(oceanbase-4.1.0.2-104000032023092119)及之后版本。