Ensure to close rs and ps in loop body to avoid ORA-01000: maximum open cursors exceeded exception:
PreparedStatement ps = null;
ResultSet rs = null;
Incorrect:
for (int i = 0; i < 500; i++) {
ps = connection.......
}
ps.close();
Correct:
for (int i = 0; i < 500; i++) {
ps = connection.......
ps.close();
}
查询监测最大游标:
SELECT COUNT(*) FROM v$OPEN_CURSOR;
SELECT COUNT(*) FROM v$SESSION_WAIT;
SELECT * FROM V$OPEN_CURSOR WHERE SQL_TEXT LIKE 'INSERT%';
SELECT * FROM V$OPEN_CURSOR WHERE SQL_TEXT LIKE 'SELECT%';
select max(a.value) as highest_open_cur, p.value as max_open_cur
from v$sesstat a, v$statname b, v$parameter p
where a.statistic# = b.statistic#
and b.name = 'opened cursors current'
and p.name= 'open_cursors'
group by p.value;
alter system set open_cursors=300 scope=spfile;
Open cursors take up space in the shared pool, in the library cache. To keep a renegade session from filling up the library cache, or clogging the CPU with millions of parse requests, we set the parameter OPEN_CURSORS.
OPEN_CURSORS sets the maximum number of cursors each session can have open, per session. For example, if OPEN_CURSORS is set to 1000, then each session can have up to 1000 cursors open at one time. If a single session has OPEN_CURSORS # of cursors open, it will get an ora-1000 error when it tries to open one more cursor.
The default is value for OPEN_CURSORS is 50, but Oracle recommends that you set this to at least 500 for most applications. Some applications may need more, eg. web applications that have dozens to hundreds of users sharing a pool of sessions. Tom Kyte recommends setting it around 1000.
分享到:
相关推荐
如果应用程序打开的游标数超过这个限制,会引发 ORA-01000: maximum open cursors exceeded 异常。下面将探讨超出打开游标的最大数的原因和解决方案。 原因 应用程序打开的游标数超过 OPEN_CURSORS 参数指定的最大...
- `java.sql.SQLException: ORA-01000: maximum open cursors exceeded`: 当打开的游标超过数据库允许的最大值时会出现此错误。检查代码中游标的关闭情况,避免资源泄漏。 8. **锁冲突** - `java.sql....
当一个应用程序尝试打开过多的游标时,可能会遇到`ORA-01000: maximum open cursors exceeded`错误,这表明单个用户尝试打开的游标数量超过了系统允许的最大值。 `ORA-01000`错误的主要原因通常是程序设计不当,...
接下来,我们讨论一个常见的Oracle错误:ORA-01000: maximum open cursors exceeded,即打开的游标数量超过了允许的最大值。这通常发生在频繁使用预编译语句(PreparedStatement)的场景中。解决这个问题有以下几个...
当程序在处理大量数据或者进行复杂操作时,可能会遇到“超出打开游标最大数”的错误,即ORA-01000异常。这个错误通常表明数据库当前打开的游标数量超过了`open_cursors`参数所设定的最大值。 首先,我们需要理解为...