views:

4324

answers:

3

What is the query to find the no. of current open cursors in an Oracle Instance?

Also, what is the accuracy/update frequency of this data?


I am using Oracle 10gR2

+5  A: 

Total cursors open, by session:

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';

Source: http://www.orafaq.com/node/758

As far as I know queries on v$ views are based on pseudo-tables ("x$" tables) that point directly to the relevant portions of the SGA, so you can't get more accurate than that; however this also means that it is point-in-time (i.e. dirty read).

Jeffrey Kemp
These 'opened cursors current' are lazily reaped by the Oracle table server; so the number you see for your application may be anomalously high without meaning you made a mistake.See http://www.orafaq.com/node/758
Ollie Jones
A: 

Here's how to find open cursors that have been parsed. You need to be logged in as a user with access to v$open_cursor and v$session.

COLUMN USER_NAME FORMAT A15

SELECT s.machine, oc.user_name, oc.sql_text, count(1) 
FROM v$open_cursor oc, v$session s
WHERE oc.sid = s.sid
GROUP BY user_name, sql_text, machine
HAVING COUNT(1) > 2
ORDER BY count(1) DESC
;

If gives you part of the SQL text so it can be useful for identifying leaky applications. If a cursor has not been parsed, then it does not appear here. Note that Oralce will sometimes keep things open longer than you do.

WW
Actually, this is a complex situation. v$open_cursor happens to show cached statements.Open cursors (the resource that can be hammered if you have a cursor / ResultSet leak) is in v$sessstat in a row named 'opened cursors current'.
Ollie Jones
@Ollie: But how does that help you identify the SQL statement that is leaking?
WW
A: 

can i able to get the full query.Even with this partial query i can able to figure out the problematic query.To prove this i need full quesry can you post the quesry or ways to get that. Thanks for your query.

cibi