Keeping track of count of open cursors

Is there a way to ask the API for a list of open cursors (or at least a count of) ?

Hi Linda,
Again, thanks for the reply.
Yes, I wanted to use it to manage cursors while closing a database. At the moment I maintain a count of open cursors myself, I do this so that I can manage the close database process.
I do this if I want to close the database:
1. Prevent new cursors from being opened (reject all db updates & queries)
2. Wait till open cursor count is zero
3. close db
However, it does mean having to wrap every query/update method in such a way that I can maintain the cursor count. I was setting up a few new databases and was just wondering if i'd missed something in the API to do this for me.
Thanks,
Joel
Edited by: JoelH on 17-Dec-2009 08:57

Similar Messages

  • Cursor.count( ) leaves open cursors?

    Hi, I am seeing a weird scenario inside a JUnit test -- they symptom is if I call cursor.count( ); in the code, and then close everything properly (I think), when I call close( ) on the environment, it throws a DB exception and claims there are cursors still open. If I comment out the call to cursor.count( ); this exception goes away.
    Example inside JUnit test:
    EntityIndex<Long, FaceEdge> subIndex = da.faceEdgeByEdgeId.subIndex(12L);
    assertFalse(cursor.count( ) == 0);
    try {
       for (FaceEdge fe : cursor) {
           assertTrue(fe.getEdgeId( ) == 12L);
       } finally {
           cursor.close( );
    }The JUnit tearDown looks like this:
    super.tearDown( );
    myDbEnv.close( );...and myDbEnv.close( ) looks like this:
    if (store != null) {
       try {
           store.close( );
       } catch(DatabaseException dbe) {
          etc.
    if(myEnv != null) {
       try {
           myEnv.close( );
       } catch(DatabaseException dbe) {
          // this gets caught and says there are cursors still open
    }The comment above is where the exception is caught. I use no other cursors anywhere, and if I comment out the line:
    assertFalse(cursors.count( ) == 0);..in the JUnit test, the exception goes away.

    Hello,
    EntityCursor<FaceEdge> cursor = subIndex.entities();
    assertFalse(cursor.count( ) == 0);I think the problem is that you're calling EntityCursor.count for an uninitalized cursor. The cursor must be advanced to the first entity before calling count() is allowed. In this situation a DatabaseException will be thrown with an "uninitialized cursor" message.
    Probably what is happening in your JUnit test is that the exception is thrown but your tearDown method still executes, or perhaps you have a finally block, and you're trying to close the EntityStore or the Environment. If you try to close the store or the environment with cursors left open, you'll get an exception telling you to close the cursors. Because of this second exception, you don't see the first exception about the cursor being uninitialized.
    I see this problem a lot in my own JUnit tests. :-) What I do is, in the tearDown method I put the calls to close the store and the environnment in a try/catch block. If an exception occurs, I print it, but I don't rethrow it. This allows the original exception (the one thrown by EntityCursor.count in your case) to be reported by JUnit. For example:
    public void tearDown() {
        if (store != null) {
            try {
                store.close();
            } catch (Throwable e) {
                System.out.println("During tearDown: " + e);
            store = null;
        if (env != null) {
            try {
                env.close();
            } catch (Throwable e) {
                System.out.println("During tearDown: " + e);
            env = null;
    }Mark

  • How to keep track of count from repeating table - INFOPATH 2007

    Hello,
    I have a repeating table with two columns: Title (dropdownlist 'A') and
    Count (integer). Let's assume the user picks Title1
    with count of 3 and next row, Title2 with count
    2. Now, I have a repeating section which contains a dropdownlist
    'B' that uses 'A' as a datasource.  I need to develop a fucntionality to put some validation on dropdownlist
    B, where you should throw error if user inserts more than 3 repeating sections that has
    Title1 and no more than 2 repeating sections where dropdownlist
    B has Title2.
    Please assist.
    Thanks
    smith

    Hi,
    To get the count of the repeating tables dynamically with custom logic, custom code behind the InfoPath form will be required.
    The link below will show how to count the total amount of sections in a Repeating Section in InfoPath on the change event of the repeating section, you can apply extra custom
    logic to it to meet your requirement:
    http://www.bizsupportonline.net/infopath2007/programmatically-count-total-amount-repeating-sections-infopath.htm
    Another two links about how to work with InfoPath form programmatically for your reference:
    http://msdn.microsoft.com/en-us/library/bb509311(v=office.12).aspx
    http://blogs.msdn.com/b/infopath/archive/2010/03/18/introduction-to-programming-in-infopath-2010.aspx
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • 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.

  • Adding a counter that keeps track of the total number of times a loop has run, even if LabVIEW has been restarted.

    Hi all,
    I am writing a VI for measuring data and inserting it into a database. The measurements are controlled by a loop that runs once every minute. I want to give each measurement a unique id number and store this too in the database.
    To do this, I want to add a counter to this loop so that I can count the number of times the loop has executed in total. This is, even if the VI, LabVIEW or even th PC is restarted, I want the counter to keep track of the number of executions. If say, the loope executes two times and then the VI is stopped and restarted, I want the following number on the counter to be three.
    Does anyone have an idea about how to do this? I am gratefule for any help!
    Clara
    Message Edited by Clara G on 05-11-2010 08:21 AM
    Solved!
    Go to Solution.

    Not allowed to give away code but I can describe one of my "Totalizers" used to keep track of how much stuff has passed through a fliter so we know when to change it.
    THe Total izer is implemented as an Action Engine.
    It has three actions (methods)
    1) Init - Opens an ini file and reads the last values read and cahces these in shift registers. It also inits a timer so we now how long since the last file I/O.
    2) Update - Uses the data passed by the caller to update the totals. It also checks how long since the last save and if more than one minute it writes to the ini file (forced write).
    3) Read - returns the totals for display and evealuating if a an alarm should be triggered to change the filter.
    Note:
    THe pre-LV 8.6 version of the ini file exposed methods to allow writing to the file. The new ini functions do not expose that functionality and require closing the file.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • My iTunes doesn't keep track of my listening history anymore. It doesn't update play counts and default "Recently Played" playlist.

    My iTunes doesn't keep track of my listening history anymore. It doesn't update play counts and default "Recently Played" playlist. But it still tracking plays from my iPhone and syncing them.
    I've tried to repair it with setup file. Nothing's changed.
    Can you help me with that?
    NOTE: Now I tried disabling the crossfade feature and it worked, started to count again. But I like crossfade, I don't want to keep it off.

    I think I got this figured out. The playcount does update, but not how the previous iPod models update their playcount. Instead of immediately updating the playcount right after you finish the song like the older iPod models, iPod Touch keeps the updates in memory. The next time you connect to iTunes it'll sync those playcounts in memory to the actual songs itself, effectively updating the playcount of the songs only after connecting to iTunes. I have set my syncing manually. That's why after connecting to iTunes, my playcounts are updated. BUT it doesn't solve the mystery of my Smart Playlist. Even though in iTunes, the correct songs are listed, in the iPod Touch, it shows the old playlist.
    Don't you just hate that? It was working fine before on non-iPod touch models. Now we have to live with this new bug. I just hope when they release software 2.0 it fixes these bugs and that they *give it for free!* People shouldn't be charged on something they should have gotten as a support!

  • Where is the file that keeps track of which mail items were open?

    Searching for the file that keeps track of which mail items were open- sometimes it suddenly is shorter, forgets some of the items of mail that was open, in my 'in box' as it were.
    just happened to me- 15 emails I wanted to keep open till I answered them are now lost back in the mail stack
    any idea where i can find that, retrieve from a backup done last week?
    any trick to fixing this problem?
    hope so
    i gotta track down some of those emails, will be a huge chore to do it one by one
    thanks

    any idea where i can find that, retrieve from a backup done last week?
    Good luck with that; it's not likely to happen.
    any trick to fixing this problem?
    You could just reply to the email right away, rather than putting it off until later, whenever "later" happens to be. Or, you could also put your emails that have not yet been replied to in a separate folder, and move them out into your Inbox when you have replied.
    Mulder

  • Need to keep track of URL and a count variable

    Can anyone suggest the best way to keep track of a URL and a count variable associated with each URL. I have started using 2 List objects. When I add a URL I also add a 1 in the count List Object. I am using List Objects because I must be able to sort them and search through them.
    Can anyone verify that I am going about this the correct way?
    Thanks

    I would probably use a TreeMap that referenced the counter.

  • "Current Open Cursors Count" Warning

    I am getting this warning lately in my Grid Control repository database
    Metrics "Current Open Cursors Count" is at 1563
    Open cursors value fluctuates between 1400 and 2300.
    Is my open cursor threshold set too low (warning: default 1200, critical: not defined) and this is normal Grid Control behavior or I have some kind of problem here?
    Oracle 10g Grid Control (10.2.0.5)
    Linux x86

    Actually, it is just a message telling you that the Open Cursor Count has exceeded the threshold limit. If the number of open cursors continues to increase over time (from day to day, and constantly gets larger and larger, never gets smaller) then it may indicate a problem.
    I would suggest that you set the threshold to at least 2300, then wait and see if the alert shows up again. If it does then further analysis may be required to determine the root cause.
    I hope this helps!
    Edited by: CowTown_dba on Sep 22, 2010 10:01 AM

  • IPod and car stereo.  Will it keep track of the play count?

    I'm currently shopping around for a head unit for my car. I was just hoping someone could tell me whether or not the iPod still keeps track of play count when connected through a USB cable to the car stereo. I'm only wondering because I wasn't sure if this situation is similar to hooking and iPod to an XBOX 360 through the USB cable (which doesn't keep track of play count). If someone could please tell me what models do and don't keep track of play count, I'd really like to know. I'm particularly interested in the Alpine iDA-X305 so if someone could let me know about that one specifically, I'd really appreciate it.
    Thank you for reading my post, and I appreciate any and all help given.

    Kenichi Watanabe wrote:
    I don't think an car audio device would be smart enough to set up a connection that is like a computer's connection to an iPod. When I use my dumb docking speaker, the play count is kept for the next sync with my Mac.
    So do you think it just has to do with the fact that an Xbox 360 is pretty much a computer, therefore the iPod reads the connection as though it was a connection to a computer?

  • Keeping track of play count

         I like to keep a steady rotation with the music I play on my iPod (5th gen.).  I do this by deleting songs that have played once or twice.  The iPod used to keep track of this and would reflect the number of plays in iTunes.  Recently this has stopped alltogether.  How do I get the play count to start working again?

    Have you looked at the previous discussions listed on the right side of this page under the heading "More Like This"?

  • Current Open Cursors Count growing and growing

    Current Open Cursors Count appears to be a cumulative count and always growing since instance is started.
    Warning threshold of 1200 occurs quickly and regular warnings appears on OEM.
    (Oracle 10.1.0.4 on RHEL4AS Linux fresh install)
    The value reported on OEM correspond to:
    select name,value from v$sysstat where name like '%cursors current%';
    result: opened cursors current 194209
    Current open cursors are not
    select count(*) from v$open_cursor;
    which returns a more reasonable value: 293
    Any ideas about that ?
    Nicolas

    i have a tar opened on this .. its a bug with the database.
    After finding the query that OEM runs against the db, you
    will find that the stats the db is gathering at the database level are wrong .. they are cumulative. So until they patch the db, the metric in OEM is useless. Remove the warning/critical levels in the manage metric screen.
    NOTE: they dont use v$open_cursors .. that would be to easy :-)

  • Current Open Cursors Count

    That I have to make to correct this error
    Las métricas "Current Open Cursors Count" están en 1405
    my database sends me many messages like these. That I would have to make?
    thanks
    [email protected]

    HI,
    I had once read the following from Tom's site... I hope it will help you.
    ops$tkyte@ORA920LAP> select name, value
    2 from v$mystat a, v$statname b
    3 where a.statistic# = b.statistic#
    4 and b.name = 'opened cursors current'
    5 /
    NAME VALUE
    opened cursors current 1
    ops$tkyte@ORA920LAP>
    ops$tkyte@ORA920LAP> variable x refcursor
    ops$tkyte@ORA920LAP> variable y refcursor
    ops$tkyte@ORA920LAP> variable z refcursor
    ops$tkyte@ORA920LAP>
    ops$tkyte@ORA920LAP> exec open :x for select * from dual;
    PL/SQL procedure successfully completed.
    ops$tkyte@ORA920LAP> /
    NAME VALUE
    opened cursors current 2
    ops$tkyte@ORA920LAP> exec open :y for select * from dual;
    PL/SQL procedure successfully completed.
    ops$tkyte@ORA920LAP> /
    NAME VALUE
    opened cursors current 3
    ops$tkyte@ORA920LAP> exec open :z for select * from dual;
    PL/SQL procedure successfully completed.
    ops$tkyte@ORA920LAP> /
    NAME VALUE
    opened cursors current 4

  • Metrics " Current Open Cursors Count "

    Hi,
    I get an Alert message Metrics " Current Open Cursors Count is at 1201 '" on 10g database version 10.2.0.1.0 . Can anyone help me to solve this.
    Thanks
    Sree

    Sree,
    The Metric corresponds to the number of records in V$OPEN_CURSOR internal view.
    The number of open cursors is a function of the number of concurrent users and the application code ,so 1201 may not necessaryly indicate a problem – it could be that you system is genuinely very busy.
    You should start worrying if the number of open cursors consistently grows over time (while the workload is steady). In this case you may have a “cursor leak” – a piece of code that opens a cursor, but does not close it.
    You can check that with
    select substr(sql_text,1,30) , count(*) cnt
    from v$open_cursor
    group by substr(sql_text,1,30)
    order by 2 desc
    If the current open cursor are getting close to the max allowed(OPEN_CURSOR parameter), you may reset them using share pool flush (note that the shared pool flush may have some small performance impact on the system).
    Hope that helps,

  • Cannot figure out why "ORA-01000 Maximum open cursors" is shown...

    Hello there ...
    I am programming a PL/SQL Code that is throwing 0RA-01000 Maximum Open Cursors Exceeded.
    Having already read quite a lot about ORA-01000 errors, I know I should be closing cursors, and have already tried setting OPEN_CURSORS parameter to a high number (1000).
    I declared a lot of procedures in my pl/sql, each of which uses one cursor since i am working with a non-Oracle table linked by ODBC ... and each procedure sometimes does thousands of inserts -- but all WITHIN the explicit cursors. The explicit cursors are not declared within each loop.
    I already checked the code many times, and made sure all open cursors are closed. In addition, I also verified the numberopen cursors generated by the PL/SQL by running the following SQL after every procedure i run... and outputting it... and it appears the value just keeps on increasing, even though I had explicitly closed all the cursors in all the earlier procedures.
    What is funny is that the most number of cursors reported by the code below only hits 150+ cursors. Nowhere near the 1000 open_cursors limit per session.
    select a.value into strtxt --, b.name        
            from v$mystat a, v$statname b
            where a.statistic# = b.statistic#
            and a.statistic#= 3;When I run the procedures separately though, all the procedures run smoothly (even when I had not yet updated the open_cursors parameter).
    I was thinking of the following, but maybe you have some other ideas?
    Does this have anything to do with my procedures not being stored procedures?
    Or should i be committing records within my procedures instead of out of it?
    I really have run into a wall and would really appreciate any tips or helps on this. Thanks in advance!
    My basic pl/sql code looks like below. I did not give the actual details cause it will be too long (up to 5000 lines).
    DECLARE
    PROCEDURE proc1
    IS
        CURSOR cur_hca
           is
               select ...from..where;
       TYPE cur_hca_fetch
            Is TABLE OF cur_hca%ROWTYPE
                INDEX BY PLS_INTEGER;
        temp_collect cur_hca_fetch;
    BEGIN
       open cur_hca;         --cur_hca is the cursor name.
                                      --i use exactly the same cursor name in the other procedures
          loop
             fetch cur_hca bulk collect into temp_collect LIMIT 1000;
             exit when temp_collect.count=0
             for indx in 1 .. temp_collect.count
                loop
                  ...run some sql
                end loop;
          end loop;
      close cur_hca;
    END proc1;
    PROCEDURE proc2   --almost the same as above the only changes are the query for the
                                 -- cursor and the sql that happens for each record
    IS
    BEGIN
       open cur_hca;         --cur_hca is my cursor name
          loop
          end loop;
      close cur_hca;
    END proc2;
    ... up to 40 other very similar procedures
    BEGIN
       proc1;
       commit;
       select a.value into strtxt
            from v$mystat a, v$statname b
            where a.statistic# = b.statistic#
            and a.statistic#= 3;
      DBMS_OUTPUT.PUT_LINE('Number of Cursors After STATUSproc1: ' || strtxt); 
       proc2;
       commit;
       select a.value into strtxt
            from v$mystat a, v$statname b
            where a.statistic# = b.statistic#
            and a.statistic#= 3;
       DBMS_OUTPUT.PUT_LINE('Number of Cursors After STATUSproc2: ' || strtxt); 
       ... 40 other procedures
    END;Edited by: user4872285 on May 6, 2013 6:49 PM
    Edited by: user4872285 on May 6, 2013 7:01 PM
    Edited by: user4872285 on May 6, 2013 8:02 PM
    Edited by: user4872285 on May 6, 2013 8:03 PM

    PL/SQL code usually leaks reference cursors and DBMS_SQL cursors - as the ref cursor/DBMS_SQL interface used has a global (session static) scope.
    PL/SQL has an intelligent garbage collector that will close local implicit and explicit cursors, when the cursor variable goes out of scope.
    If you define an explicit cursor globally (package interface), then it can only be opened once. The 2nd attempt results in a ORA-06511: PL/SQL: cursor already open exception. So code cannot leak explicit cursors as code cannot reopen an existing opened explicit cursor.
    I have never seen Oracle leaking cursors internally. So I would be hesitant to call what you are seeing, a bug. If your code is using explicit cursors (even static/global ones), your code cannot leak these cursors, even if your code does not close them. Worse case - the cursor remains open, however new copies cannot be created while it is open.
    So I think your are looking at the wrong thing - explicit cursors. These are not the cursors that are leaking in my view (simply because code cannot reuse and open an already opened explicit cursor). Here is an example:
    SQL> show parameter cursors
    NAME                                 TYPE        VALUE
    open_cursors                         integer     300
    session_cached_cursors               integer     50
    // procedure that seems to "leak" an explicit cursor handle
    // as it does not explicitly closes the handle
    SQL> create or replace procedure CursorUse is
      2          cursor c is select e.* from emp e;
      3          empRow  emp%RowType;
      4  begin
      5          open c;
      6          fetch c into empRow;
      7          --// not closing explicit cursor handle
      8          --// and going out-of-scope
      9  end;
    10  /
    Procedure created.
    // current session stats
    SQL> select b.name, a.value from v$mystat a, v$statname b where a.statistic# = b.statistic# and b.name like '%open%cursor%';
    NAME                                  VALUE
    opened cursors cumulative                91
    opened cursors current                    2
    // execute proc that "leaks" a cursor, 10000 times
    SQL> begin
      2          for i in 1..10000 loop
      3                  CursorUse;
      4          end loop;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    // no errors due to cursor leakage
    // session stats: no cursor leakage occurred as
    // PL/SQL's garbage collector cleaned (and closed)
    // cursor handles when these became out-of-scope
    SQL> select b.name, a.value from v$mystat a, v$statname b where a.statistic# = b.statistic# and b.name like '%open%cursor%';
    NAME                                  VALUE
    opened cursors cumulative            10,095
    opened cursors current                    2
    SQL> So the cursor leakage you are seeing is caused by something else... so what else is part of the code, or the session, that you have not yet mentioned?

Maybe you are looking for