java.sql.SQLException: - ORA-01000: maximum open cursors exceeded

后端 未结 13 1402
鱼传尺愫
鱼传尺愫 2020-11-22 08:36

I am getting an ORA-01000 SQL exception. So I have some queries related to it.

  1. Are maximum open cursors exactly related to number of JDBC connections, or are t
相关标签:
13条回答
  • 2020-11-22 09:23

    I am adding few more understanding.

    1. Cursor is only about a statement objecct; It is neither resultSet nor the connection object.
    2. But still we have to close the resultset to free some oracle memory. Still if you don't close the resultset that won't be counted for CURSORS.
    3. Closing Statement object will automatically close resultset object too.
    4. Cursor will be created for all the SELECT/INSERT/UPDATE/DELETE statement.
    5. Each ORACLE DB instance can be identified using oracle SID; similarly ORACLE DB can identify each connection using connection SID. Both SID are different.
    6. So ORACLE session is nothing but a jdbc(tcp) connection; which is nothing but one SID.
    7. If we set maximum cursors as 500 then it is only for one JDBC session/connection/SID.
    8. So we can have many JDBC connection with its respective no of cursors (statements).
    9. Once the JVM is terminated all the connections/cursors will be closed, OR JDBCConnection is closed CURSORS with respect to that connection will be closed.

    Loggin as sysdba.

    In Putty (Oracle login):

      [oracle@db01 ~]$ sqlplus / as sysdba
    

    In SqlPlus:

    UserName: sys as sysdba

    Set session_cached_cursors value to 0 so that it wont have closed cursors.

     alter session set session_cached_cursors=0
     select * from V$PARAMETER where name='session_cached_cursors'
    

    Select existing OPEN_CURSORS valuse set per connection in DB

     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;
    

    Below is the query to find the SID/connections list with open cursor values.

     SELECT a.value, s.username, s.sid, s.serial#
     FROM v$sesstat a, v$statname b, v$session s
     WHERE a.statistic# = b.statistic#  AND s.sid=a.sid 
     AND b.name = 'opened cursors current' AND username = 'SCHEMA_NAME_IN_CAPS'
    

    Use the below query to identify the sql's in the open cursors

     SELECT oc.sql_text, s.sid 
     FROM v$open_cursor oc, v$session s
     WHERE OC.sid = S.sid
     AND s.sid=1604
     AND OC.USER_NAME ='SCHEMA_NAME_IN_CAPS'
    

    Now debug the Code and Enjoy!!! :)

    0 讨论(0)
提交回复
热议问题