Skip to Main Content
  • Questions
  • How to find, how many open_cursors active at a particular time

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Ashish.

Asked: September 11, 2000 - 7:40 pm UTC

Last updated: August 19, 2002 - 1:10 pm UTC

Version: 8.1.6

Viewed 1000+ times

You Asked

Hello Tom,

I was wondering if there is any query to find out the
number of OPEN_CURSORS active at a particular time,
in the database

When I say active I mean , if you look at some of the
data dictionary views $open_cursors it will show all
the cursors ,including ones which are not active anymore.

The reason I ask is because I used to get the
running out of OPEN_CURSORS errors will running
the application against the database (8.1.6.0).

The db OPEN_CURSORS parameter was set to 500 (which is
quite high,considerig it is per process).

The application was written in Java and was using JDBC.

Thanks

and Tom said...


Well, I have my open_cursors set to 1000. Cursors are allocated 64 at a time upto OPEN_CURSORS so having it set high it OK. You use what you need and if you don't need them all -- they aren't there.

select * from v$sysstat where statistic# = 3;

will get you the total number of current open cursors in the system.

select * from v$sesstat where statistic#= 3;

will show you by session...

select * from v$mystat where statistic# = 3;

will show you YOUR open cursor count.






Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

<> between mystat and sesstat

Alex Daher, August 16, 2002 - 4:35 pm UTC

Tom, is there any difference between V$MYSTAT and V$SESSTATS where SID = "my SID"?

I don't understand this:

system@ORACLE8> select * from v$sesstat where sid = 59 minus select * from v$mystat;

SID STATISTIC# VALUE
---------- ---------- ----------
59 15 72168
59 16 85040
59 188 20
59 190 39

Elapsed: 00:00:00.01
system@ORACLE8> select * from v$mystat minus select * from v$sesstat where sid = 59;

SID STATISTIC# VALUE
---------- ---------- ----------
59 15 72168
59 188 22
59 190 493

Elapsed: 00:00:00.01


Tom Kyte
August 16, 2002 - 6:47 pm UTC

They are the same -- when you understand whats going on under the covers, this'll be an "ah hah" sort of question.

See
http://docs.oracle.com/docs/cd/A87860_01/doc/server.817/a76961/ch3.htm#5014

which says in part:

<quote>
About Dynamic Performance Views

Oracle contains a set of underlying views that are maintained by the server and accessible to the database administrator user SYS. These views are called dynamic performance views because <b>they are continuously updated </b>while a database is open and in use, and their contents relate primarily to performance.

Although these views appear to be regular database tables, <b>they are not.</b> These views provide data on internal disk structures and memory structures. You can select from these views, but you can never update or alter them.

Notes:

    * You can query the dynamic performance views to extract information from them. However, <b>only simple queries are supported.</b> If sorts, joins, GROUP BY clauses and the like are needed, you should copy the information from each V$ view into a table (for example, using a CREATE TABLE ... AS SELECT statement), and then query from those tables.

* Because the information in the V$ views is dynamic, <b>read consistency is not guaranteed for SELECT operations on these views.</b>
....
</quote>

That last part -- about read consistency -- is the kicker.  I've modified your queries a tad so we can see the stats that were different:

ops$tkyte@ORA817DEV.US.ORACLE.COM> column sid new_val s
ops$tkyte@ORA817DEV.US.ORACLE.COM> select sid from v$mystat where rownum=1;

       SID
----------
        18

ops$tkyte@ORA817DEV.US.ORACLE.COM> 
ops$tkyte@ORA817DEV.US.ORACLE.COM> 
ops$tkyte@ORA817DEV.US.ORACLE.COM> select a.name, b.value
  2    from v$statname a, v$sesstat b
  3   where a.statistic# = b.statistic#
  4     and b.sid = &S
  5  MINUS
  6  select a.name, b.value
  7    from v$statname a, v$mystat b
  8   where a.statistic# = b.statistic#
  9  /
old   4:    and b.sid = &S
new   4:    and b.sid =         18

NAME                                VALUE
------------------------------ ----------
session pga memory                 119152
session pga memory max             119152
session uga memory                  53456
session uga memory max              57900
sorts (memory)                          0
sorts (rows)                            0

6 rows selected.

<b>what that is saying is the when we processed the v$sesstat table, we were using 119,152 bytes of PGA memory.  When we processed v$mystat -- we had some DIFFERENT amount of PGA memory -- by the time we got there, it was different, hence the minus shows us the row from v$sesstat.

Now, the sorts are just the same -- you KNOW a minus needs a sort right (no indexes here).  Well, when we scanned v$sesstat, we hadn't sorted yet.  By the time we got to v$mystat -- WE HAD</b>

ops$tkyte@ORA817DEV.US.ORACLE.COM> select a.name, b.value
  2    from v$statname a, v$mystat b
  3   where a.statistic# = b.statistic#
  4  MINUS
  5  select a.name, b.value
  6    from v$statname a, v$sesstat b
  7   where a.statistic# = b.statistic#
  8     and b.sid = &S
  9  /
old   8:    and b.sid = &S
new   8:    and b.sid =         18

NAME                                VALUE
------------------------------ ----------
session uga memory                  53456
sorts (memory)                          6
sorts (rows)                         1416

ops$tkyte@ORA817DEV.US.ORACLE.COM> 

<b>what that shows us is the memory usage sort of settled down, little different UGA numbers but that is it.  Again the sort numbers come out but that is expected -- the first query must have done 4 sorts of 1,416 rows and by the time we got to v$sesstat in this query -- we had done more!

Sort of 'neat', unexpected maybe -- but 'neat'.

Here is the topper:</b>

ops$tkyte@ORA817DEV.US.ORACLE.COM> select a.statistic#, a.value, b.value
  2  from v$mystat a, v$mystat b
  3  where a.statistic# = b.statistic#
  4  and a.value != b.value;

STATISTIC#      VALUE      VALUE
---------- ---------- ----------
        15      61728      53456
       188         13         12
       190       3072       2832

<b>Hmmmm</b>


 

Hummm... ah-hah

Alex Daher, August 19, 2002 - 8:12 am UTC

Right!!! Now It's much clearer... :-)

Thank you again, Tom!

Very interesting...

A reader, August 19, 2002 - 1:10 pm UTC