KB · Oracle Database · Fix

"ORA-01000: maximum open cursors exceeded": find the sessions holding them

Oracle Database · Fix · Verified on Oracle 23ai · Updated 2026-12-03

Error this answers

  • ORA-01000: maximum open cursors exceeded

Symptom

An application starts failing with:

ORA-01000: maximum open cursors exceeded

usually from one app and usually after it has been up for a while.

Why it happens

Each session can hold at most open_cursors cursors open at once. Applications leak them when they open a statement or result set and never close it, which is common with JDBC code that skips close() in error paths. The leak grows with uptime until a session hits the limit.

Check

Find sessions above a threshold, grouped by machine and SQL (cur.sql) or by machine only (cur2.sql):

SQL> show parameter open_cursors
SQL> @cur.sql 200

Pick a threshold below open_cursors so you see who's close to the limit, not just who has hit it.

cur.sqlMIT · Download ·
-- cur.sql: sessions holding more than N open cursors, grouped by machine and SQL
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/open-cursors-by-session/
--
-- Usage: @cur.sql <cursors>
--        @cur.sql 200

set lines 132
set trims on
col machine format a35


select count(*), inst_id, machine,status,sql_id,prev_sql_id
from gv$session
where (inst_id,sid) in (select st.inst_id, st.sid
                         from gv$sesstat st, v$statname n
                        where st.statistic# = n.statistic#
                          and n.name = 'opened cursors current'
                          and st.value > &&1)
group by inst_id,machine,status,sql_id,prev_sql_id;


undefine 1

curl -O https://hashjoin.com/kb/oracle/open-cursors-by-session/cur.sql

cur2.sqlMIT · Download ·
-- cur2.sql: the same, grouped by machine only
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/open-cursors-by-session/
--
-- Usage: @cur2.sql <cursors>
--        @cur2.sql 200

set lines 132
set trims on
col machine format a35


select count(*), machine,status
from gv$session
where (inst_id,sid) in (select st.inst_id, st.sid
                         from gv$sesstat st, v$statname n
                        where st.statistic# = n.statistic#
                          and n.name = 'opened cursors current'
                          and st.value > &&1)
group by machine,status;


undefine 1

curl -O https://hashjoin.com/kb/oracle/open-cursors-by-session/cur2.sql

Fix

Verify

Run cur.sql again after the app fix is deployed and the pool has cycled. The same machines should no longer show up at your threshold.

Gotchas

What it reads

gv$sesstat v$statname gv$session

Tired of fixing the same thing twice?

HASHJOIN turns the checks and fixes your on-call runs by hand into tooling that gives the same answer every time. Fixed scope, and you own all of the code.