Code Snippet

Just another Code Snippet site

[Oracle] Retrieve current SGA, PGA, Nb Processes, Nb Cursors

set serveroutput on
SPOOL /tmp/oracle_stats.log

DECLARE

CURSOR C_STATS IS
    select * from
    (
    select 'process='||current_utilization as val from v$resource_limit where resource_name in ('processes')
    --
    union
    --
    select 'cursor='||max(a.value)  as val
    from v$sesstat a, v$statname b
    where a.statistic# = b.statistic#  and b.name = 'opened cursors current'
    --
    union
    --
    select 'sga='||trunc(sum(bytes)/1024/1024) as val from v$sgastat where name!='free memory'
    --
    union
    --
    select 'pga='||trunc(value/1024/1024) as val from v$pgastat where  name = 'total PGA inuse'
    )
    order by 1;


BEGIN

    FOR stats IN C_STATS LOOP

        dbms_output.put_line(stats.val );

    END LOOP;

END;
/

SPOOL OFF;
exit;


Comments are currently closed.