Metrics "Current Open Cursors Count" is at %

La metrica "Current Open Cursors Count" conta il numero totale di cursori aperti del database nello stesso istante.

Che cosa è il Cursor?
Ogni volta che viene eseguia una SQL statement, viene allocata una quantità di memoria privata nella Shared pool, e in dettaglio nella Library Cache, chiamata Cursor o Context Area.
Proprio per eviare che una sessione rinnegata riempia la Library Cache o ostruisca la CPU con milioni di richieste di analisi (PARSE), viene impostato il parametro del database OPEN_CURSORS che limita i cursori aperti contemopranemante per sessione.

SQL> show parameter open_cursors

Il parametro OPEN_CURSORS imposta il numero massimo di cursori per sessione, che ogni sessione può avere aperti.
Ad esempio, se il valore di OPEN_CURSORS è impostato su 1000, ogni sessione può avere fino a 1000 cursori aperti contemporaneamente.


Le soglie sono visibili nelle seguente query
SQL> select * from dba_thresholds where metrics_name like 'Current Open Cursors Count%'



Il numero totale di cursori aperti per sessione.
--total cursors open, by session

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'
    order by 1 desc;


--total cursors open, by username & machine

SQL> select sum(a.value) total_cur, avg(a.value) avg_cur, max(a.value) max_cur,s.username, s.machine
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'
group by s.username, s.machine
order by 1 desc;


Questo alert ricevuto da EM indica che c'è uno schema con un numero eccessivo di cursori aperti.
Ad esempio un' applicazione che chiama uno schema e che non chiude i cursori.
V$OPEN_CURSOR è la vista dei cursors che ogni user session  ha attulmento aperto ed elaborato (parsed).

SQL> select user_name, count(*) from v$open_cursor group by                user_name;

USER_NAME     COUNT(*)
----------------------------------------
EGS_OWN   10
FPERST        273
ARESCO      502
DBSNMP     63
ACDCS       1330
SYS             159
GP C           20

Individuo così lo schema incriminato che è ACDCS.

Dalla query seguente invece risalgo al testo del sql.

SQL> select  sql_text, count(*) as "OPEN CURSORS", user_name 
    from v$open_cursor 
   group by sql_text, user_name 
    order by count(*) desc;

Per risalire al SID che ha più cursori aperti

SQL> select sid, count(*) 
    from v$open_cursor 
    group by sid order by 2 desc;

A questo punto si può analizzare il problema con i developer dell'applicazione per trovare una soluzione.


Per visualizzare qual'è ora il massimo valore di Open Cursor rispetto al parametro impostato per il database:

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

Se le sessioni sono in esecuzione vicino al limite, aumentare il valore del parametro OPEN_CURSORS.
E' un parametro dinamico che può essere aumentato senza riavviare il db.

SQL> alter system set open_cursors=400 scope=both sid='*';


Su Enterprice Manager è visibile sotto "Tutte le metriche" > "Limiti del database"



 

Post popolari in questo blog

ORA-12154: TNS: il listener non è attualmente a conoscenza del servizio richiesto nel descrittore di connessione

Create e Drop Pluggable Database