ORA-01000: maximum open cursors exceeded

1972 단어 OaclesqlWebcacheUP
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.

좋은 웹페이지 즐겨찾기