Number of open cursors

I'm working on debugging some code and trying to monitor some of things that are happening at runtime. One of the things that would be useful is if I could monitor the number of open cursors on a connection.
I've done my searching and can't seem to find anything of the sort Connection.getOpenCursorCount().... is there such a method or anything related?

There's nothing generic like this, every possible approach that I know of is implementation-specific, either Java-side or DB-side.
The Java-side approach is to attempt to track ResultSets through their life-cycle, as a rough proxy for cursors; this usually relies on wrapped RSs or a vendor-specific driver feature, and is sometimes not a good solution for running down certain types of resource leaks.
On the DB side, some DBs have some visibility into open cursors through some sort of vendor-specific API.
For example, on Oracle, there is the system view V$OPEN_CURSOR that can be queried for some information related to open cursors, often in conjuction with info ftom V$SESSION and V$SQL, V$SQL_AREA or V$SQL_TEXT. IMPORTANT NOTE: this view is actually a view on internal Oracle memory structures. While you can query it like any normal view or table, it is changing constantly, with internal per-row consistancy guaranteed by latches (locks on memory). Complex queries against internal views (such as self-joins or complex aggregations) can interact with the latches very badly; the queries may take many hours to complete and consume massive amounts of CPU while doing so. If you need to perform a complex analysis, don't do it on the live view; create a snapshot of the view and use that, for example:
CREATE TABLE SNAP_OPEN_CURSORS as
SELECT * FROM V$OPEN_CURSORS(Note that in a RAC or OPS Oracle cluster, the V$ views only report on the instance you're connected to; there are analogous GV$ views that report on all available instances, and have an added INST_ID column identifying the source instance, when relevant).

Similar Messages

  • How to get highest number of open cursors within the current calendar day

    Hi all ,
    i need to know how to get the highest number of open cursors within the current calendar day.
    Thanks ,

    823030 wrote:
    the issue is my customer is getting the error ORA-01000: maximum open cursors exceeded and we need an sql statment that gets the following values :
    -highest number of open cursors experienced in the current calendar day.
    -current open cursors
    -and maximum open cursorsThis error is rare. It happens when
    a) the value of the open cursor parameter is set extremly low (default is something like 1000). Low would be something like 10.
    b) <strike>you have many concurrent users(=sessions) and </strike>the application does not use bind values
    In this case each select will open a new cursor, instead of reusing it.
    c) you have a select that opens a cursor for each line. This can happen with a statement where you have the CURSOR keyword somewhere in the select or where clause. Those cursors will be closed when the select is finished. But during the run time of the select, all cursors stay open.
    To track the number of "open cursors" during the day you would need to implement some monitoring. Maybe based on the view that was already mentioned.
    Edited by: Sven W. on May 16, 2011 2:30 PM - since the parameter is on session level, other open cursors should not influence it much.

  • Avg number of open cursors per session

    We've been noticing a large number of open cursors open per session in our database, these users being Oracle Forms users. There are quite a few 'bells & whistles' in this vendor-supplied application with many round trips to the database. The warning we were receiving was induced by an alert that we had set up within OEM.
    It got me wondering then, what a large number of cursors per process really was. We're seeing between 10-80 open cursors. The init parm OPEN_CURSORS has a default value of 50 upon installation (which is per session), so the max of 80 doesn't seem too much higher.
    Are we really experiencing a large # of open cursors per session? Does someone have a means of estimating the max # of cursors that one would expect based upon CPU & memory resources? I can't find anything in the documentation.
    Thanks,
    Chuck

    There is an OPEN_CURSORS parameter in the init.ora file,
    I want to know the impact of number of open cursors on performance
    (ie., how many open cursors would be appropriate for an instance)There shouldn't be a performance issue here. The value needs to be set based on how many open cursors you want to allow simultaneously. If you set the value too low, applications will get the "too many cursors open" error when they try to open a new cursor. If you're not having problems, or if you don't know how many open cursors you're likely to have, I wouldn't change this parameter.
    Justin

  • Question about trigger to check the number of open cursors

    Hello.
    I wonder if it is possible to create a trigger that fires when the number of open cursors in a database becomes larger than a certain number. What kind of trigger and how would it be?
    If it were possible the trigger would write traces with the timestamp of the event.
    I would also like some pl/sql tester that would increase the number of open cursors so that I could check the trigger.
    Thanks in advance.

    Satish Kandi wrote:
    OPEN_CURSORS is a value per session and not for the entire database. So if your cron job is looking for a global cumulative value of open cursors to occur in a single session, it won't find any such sessions.
    Is it the case?Yes, I am afraid it is.
    I am sorry but I don't unsertand what you are telling me: doesn't "select count(*) from v$open_cursor" count the number of open cursor for all sid columns in the view?
    The cron launches a scripts that connects to the database via sqlplus whereas there is a java application (several threads without connection pooling) that connects to the database via jdbc and that causes the problem once in 5 months (to say something).
    Thanks again.
    Edited by: fsanchezherrero on Jul 3, 2009 12:28 PM
    Edited by: fsanchezherrero on Jul 3, 2009 12:36 PM

  • Increased maximum number of open cursors

    I'm using JDBC with oracle. And I need to send many transactions to database.
    I use Statement.executeQuery("INSERT INTO ..............") and so on!
    But after 300 transaction Oracle send me an error that "increased maximum number of open cursors." How to increase the max number of that cursors or how to close them??
    Thanks in advance!

    1. Use, PreparedStatement instead of Statement.
    2. Use addBatch() and executeBatch() methods.
    3. Don't create statement objects in a loop, just create one object outside the while (or for) loop and use the same object again and again. Most probably the problem may be due to creating excessive object in a llop.
    Hope this helps.
    Sudha

  • 'number of open cursors exceeded' exception - 10.3.1

    Hi All,
    We have may DynamicSQL statements fired from our processes due to which we are getting 'number of open cursors exceeded' exception. We don't want to increase the limit of the maximum open cursors. Is there any way to close the cursors explicitly in 10.3.1?
    I am aware that when the iterator fetches the last result the cursor gets closed (in the case of any select query) but we have faced the same issue once/twice in the insert query also, is it because we have fired one insert after the other immediately? How much time does a cursor takes to close (implicitly) in the case of insertion of data?
    Thanks in advance..
    Edited by: GBP on Jan 5, 2011 4:07 AM

    Hi,
    Please see my post: Re: Cursor closing using DynamicSQL.executeQuery
    Hope this helps,
    Ariel

  • How to analyse the number of open cursors being used by each program?

    Hi,
    I am getting an error "ORA:1000 Maximum Open Cursors Exceeded" in my
    application. I want to analyse and monitor that how many cursors are
    being used  by each program running in a particular session. I have
    already set the Open Cursors Count double of the recommended for my
    application, yet I am getting this error.
    Is there any tool to analyse and monitor the number of cursors being
    used by each DB call?
    I have installed SAP NW 7.0 and Using Oracle 10g as DB.
    Your immediate help will be greatly appreciated.
    Best Regards,
    Smriti.

    You can list the open cursors per session and check which one uses the most with sqlplus:
    SQL> 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';
    Values over 300 are unusual.
    It is quite possible, that you see several workprocesses using a lot, because workprocesses are kind of shared sessions.
    Cheers Michael
    Edit: ah, our posts crossed, obviously there is no workprocess in the java world

  • How to get number of open cursors per connection?

    I am trying to make sure my connection pool handles all
    situations where I need to close and reopen a Connection
    object.
    The last criteria I am trying to check is, how many open cursors
    are there on a connection that is supposedly no longer in use?
    If my application tells my Connection pool class that a
    Connection is not in use anymore, the Connection can be
    reused unless there are too many open cursors. I'm closing all my
    statments, but I want to make sure that I've got this check in
    place.
    TIA,
    Mike
    null

    I am trying to make sure my connection pool handles all
    situations where I need to close and reopen a Connection
    object.
    The last criteria I am trying to check is, how many open cursors
    are there on a connection that is supposedly no longer in use?
    If my application tells my Connection pool class that a
    Connection is not in use anymore, the Connection can be
    reused unless there are too many open cursors. I'm closing all my
    statments, but I want to make sure that I've got this check in
    place.
    TIA,
    Mike
    null

  • Open cursors problem- j2ee + oracle 10g

    Hi,
    I am using EJB on sunOne application server 8.1., Oracle 10g DB.
    EJB container connects to Oracle DB through a set of connection pools.
    BMP for all entity beans.
    I have about 160 PL/SQL functions that make up the business logic of the online application. everytime the application runs, I get an increasing number of open cursors, including some of the ones that are explicitly closed within PL/SQL (inspection with sys.v_$open_cursor).
    I made sure all CallableStatements, PreparedStatements, RecordSets within the beans are closed and set to NULL. All PL/SQL functions use explicit cursors, so every select statement is managed within a cursor which is explicitly closed when the function finishes with it.
    From v$open_cursor, I identified the sessions with the cursors still open, and issued (ALTER SYSTEM KILL SESSION �sid, #serial�) for each of the sessions (this is done via a PL/SQL function for all inactive sessions).
    These sessions have state INACTIVE, and wait_class IDLE. This has Killed all sessions, but I was not able to use the application anymore. I suspect by killing those sessions we have also caused the connections between EJB container and the Oracle DB. The only way to use the application now is to stop and restart the sunONE domain � this is very inconvenient.
    Has anyone encountered a similar problem? any suggestions to reduce or eliminate the open cursors number? Please help.
    Thank you all

    Maybe you can try to have a smaller steady-pool-size and idle-timeout-in-millis for your connection pools.
    Also, if that's at all possible, have smaller number of connection pools being shared by more apps.
    Just my 2c.
    thanks.

  • Open cursors and shared cached cursors

    Hi
    In addm report i found below recommendation, before any change in parameter i want to know about those parameters, is there any thumb rule for this parameters,
    is there any drawback if i increase those parameters.
    FINDING 7: 2.1% impact (10693 seconds)
    Soft parsing of SQL statements was consuming significant database time.
    RECOMMENDATION 1: Application Analysis, 2.1% benefit (10693 seconds)
    ACTION: Investigate application logic to keep open the frequently used
    cursors. Note that cursors are closed by both cursor close calls
    and
    session disconnects.
    RECOMMENDATION 2: DB Configuration, 2.1% benefit (10693 seconds)
    ACTION: Consider increasing the maximum number of open cursors a
    session
    can have by increasing the value of parameter "open_cursors".
    ACTION: Consider increasing the session cursor cache size by
    increasing
    the value of parameter "session_cached_cursors".
    RATIONALE: The value of parameter "open_cursors" was "300" during the
    analysis period.
    RATIONALE: The value of parameter "session_cached_cursors" was "20"
    during the analysis period.
    Thanks and Regards
    Jafar

    Jaffy
    Your system suffers from soft parsing (according to ADDM), therefore:
    - Increasing the value of open_cursors has no impact on soft parsing (only up to 9.2.0.4 open_cursors had a direct impact on that for PL/SQL programs).
    - Increasing the value of session_cached_cursors might help reducing soft parsing. If it helps or not is really dependent from the application.
    ADDM is probably advising to increase open_cursors as well, because the database engine will keep cursors open even if the application closes them.
    HTH
    Chris
    PS: cursor_sharing might be helpful to reduce hard parses. It has no impact on soft parses... So, forget the hint about it.

  • Viewer leaving open cursors in Oracle

    We are using the JRC to display reports in our software. We are running jboss-4.2.0 as our application server. The backend could be either SQL Server or Oracle. For Oracle we are using the oracle.jdbc.driver.OracleDriver driver. The reports are set up using a JDBC (JNDI) connection. Generally we have it working ok but in Oracle the JRC is leaving open cursors leading to  ORA-01000: MAXIMUM OPEN CURSORS EXCEEDED. I have found that a new cursor is opened when the data source is changed in the following code snippet
    Iterator tableIT = tableNames.iterator();
    while (tableIT.hasNext()) {
      ITable oldTable = (ITable)tableIT.next();
      ITable table = (ITable) ((IClone)oldTable).clone(true);
      table.setQualifiedName(table.getName());
      clientDoc.getDatabaseController().setTableLocation(oldTable, table);
    When we hit the last line in this loop, a new cursor is opened in Oracle so if a report has 10 tables, I get 10 cursors opened. I know that I need to close the cursors somehow but nothing I do seems to make a difference. After my processHttpRequest call to the viewer I added:
    crystalReportPageViewer.getReportSource().dispose();
    clientDoc.getReportSource().dispose();
    The code definately executes but the the number of open cursors in Oracle does not change. I am at a loss.

    A couple more things to think about then.
    1.  When you go through your loop to set your table location, you are using the clone method to create a new table and then pass that table to the report.  Cloning tables is no longer necessary with the JRC.  We do know that a fix was provided for the JRC SDK, however this fix would probably not have been applied to the clone method since it has been deprecated.
    I have attached a sample that shows the new methodology for setting table location; very similar, just not using clone anymore.
    2.  When you want to destroy any connections that the ReportClientDocument has made, you will need to call .close() on this object.  This can be done in conjunction with the viewer.dispose().  One thing to note is that if you call the .close() method, it will need to be done as the user is closing the browser, or you will not have access to your report object when you have it open in the HTML Viewer.

  • Maximum open cursors exceeded with Sybase TG

    Hi,
    Does anyone knows if we can use the HS_OPEN_CURSORS with Oracle transparent gateway for Sybase ?
    I've got the error message :
    ORA-01000: maximum open cursors exceeded
    Thanks

    This depends if the maximum number of cursors exceeded in the GTW or within the db.
    In my eyes the OPEN_CURSORS of the db is normally the limiting factor.
    HS_OPEN_CURSORS defines the maximum number of cursors that can be open on one connection to a non-Oracle system instance.
    The value never exceeds the number of open cursors in the Oracle database server. Therefore, setting the same value as the OPEN_CURSORS initialization parameter in the Oracle database server is recommended.
    So better check out the OPEN_CURSORS of the db and increase them.

  • Bug: Maximum # Open Cursors

    Raptor is somehow managing to reach the maximum number of open cursors on the database I'm connected to.
    Database: 9.2.0.4
    Raptor 919
    XP
    Open_cursors param: 50
    I had this error yesterday, after faffing around lots in Raptor - I managed to recreate it today, by going through each table and selecting each tab in turn, plus opening packages, views, indexes, etc.

    Heard from the developer.
    The way our grids work is to only bring back as much data as needed for display. But they keep the result set open so that more data can be fetched. So I can see how we can rack up the cursor count. Not a good thing. We need to make sure that every time we switch to a new Table, we are closing all the ResultSets from the previous Table.
    This is now logged as a bug and we will be working to fix it right away.
    Thanks again for reporting this!
    -- Sharon

  • How to close open cursors in a forms app

    All,
    I'm not a forms developer. I'm a database administrator so I'm asking this question from that perspective. I know nothing about forms development.
    We have several forms applications that appear to hold many SELECT cursors open when they run. I've asked my forms developers about this and they are giving me the idea that they don't have much control over this. I have no idea myself so I'm asking here.
    When one issues selects from a form, do those selects remain as open cursors while the form runs? Is it possible to close those select cursors from within the form so that the application does not keep so many cursors open simultaneously?
    I am typically seeing a forms application with 70-100 open cursors. And we have hundreds of end users each running the forms application which is causing a lot of problems with the sheer number of open cursors.
    I've already bumped the database OPEN_CURSORS parameter but it's my feeling that developers should be doing a better job of closing cursors from within the form.
    Can anyone give me some guidance here or point me to some documents that describe how to reduce the number of open cursors to the database from a forms app?
    Thanks,

    There are several ways Forms use cursors. In the standard default method, users enter a query where condition and then execute the query. This process opens a cursor on the server, and the form fetches a few (20 or so) rows and displays on the screen (in a base-table "block"). If the user scrolls down, more rows are fetched from the cursor. This can go on and on if the user keeps scrolling down through the data. I am not sure when the cursor gets closed -- there is no Forms command to close this one. Only closing the form, or else re-executing the query process would close such a cursor.
    In the PL/SQL code, where the developer has control, a cursor can be opened, rows fetched, and then closed. This can be done either with Open-Fetch-Close or in a For... Loop. The developer can explicitly close this cursor, or PL/SQL theoretically closes the cursor when the block of code is exited.
    There is of course the SQL Select into, but that only works in PL/SQL for single-row selects. I doubt this is a major problem.
    And finally, there are the record groups, where Forms runs the select to draw all the data into an array in the form. These should be closed automatically, I believe.
    Now... if you can determine which tables the cursors are remaining open, maybe your developers can zero in on the forms, and maybe clean up some things. However, I am doubtful much can be done. It seems to me that if the open cursors are causing some database sluggishness, then maybe adding more memory on the server is the best option.

  • Multiple statements from one connection causes ORA-0100 Maximum open cursor

    HI,
    I am creating a connection and trying to run 2 statements off the connection. The connection has autocommit as false as I want to commit only after the second statement commits successfully. Upon executing the second statement, I get the ORAC-0100: Maximum open cursor error. I have verified that I have closed all the Preparedstatement and ResultSet in the first statement.
    My code looks like this:
    Connection myConn = DriverManager.getConnection(jdbc:oracle:thin:.....); myConn.setAutoCommmit(false); Savepoint sp = myConn.setSavePoint("save1"); PreparedStatement pstmt = myConn.prepareStatement(...) ResultSet rs = pstmt.executeQuery(); while (rs.next()){ ..... } rs.close(); pstmt.close(); rs=null; pstmt=null; Statement stmt2 = myConn.createStatement(); sql="DELETE FROM TempTable..."; stmt2.executeUpdate(sql);
    I put a breakpoint just before stmt.executeUpdate and verified the open cursor are below the threshold. And as soon as I execute stmt2.executeUpdate,I get the maximum cursor error. Also, I noticed that the number of open cursors jumps to the limit after stmt2.executeUpdate(sql) as verified by the following sql
    select s.sid, s.username,  a.value 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 s.username = 'user_name';
    Am I doing something wrong? Is there a better way to execute multiple statements using the same connection and commiting only after the last statement has executed successfully?

    I believe you need to close your connection via myConn.close() as follows:
    PreparedStatement pstmt=null;
    ResultSet rs=null;
    Connection myConn=null;
    try{
    myConn= //put code to get connection in this statement here
    pstmt = myConn.prepareStatement(...)
    rs = pstmt.executeQuery();
    while (rs.next()){
    }finally{
    if(rs!=null)
    rs.close();
    if(pstmt!=null)
    pstmt.close();
    if(myConn!=null)
    myConn.close();
    }

Maybe you are looking for