Search This Blog

Total Pageviews

Tuesday 25 October 2011

Oracle PGA report

Oracle PGA REPORT  ... 




pga report

PGA Diagnostics

from web http://oracle-cookies.blogspot.com/2007/08/pga-diagnostics.html
-- PGA Report
-- Displays various statistics regarding the PGA usage

set linesize 300 pagesize 400 heading off  feedback off

-- general statistics
select 'SECTION 1: GENERAL STATISTICS FOR THE PGA' from dual;
select '==================================================================' || '=========================' from dual;

set heading on
select name,
       decode(unit, 'bytes', round(value / 1024 / 1024, 2), value) value,
       decode(unit, 'bytes', 'MB', '') unit
  from v$pgastat;

set heading off
select 'Check the following:' from dual;
select '  - "aggregate PGA auto target" should not be too small in comparison '  || 'with the "aggregate PGA target parameter"' from dual;
select '  - "global memory bound" should not be lower than 1M' from dual;
select '  - "over allocation count" should be near 0 or should not increasing in time' from dual;
select '  - the bigger "cache hit percentage", the better' from dual;
select '' from dual;

set heading on
SELECT name profile, cnt, decode(total, 0, 0, round(cnt*100/total)) percentage
    FROM (SELECT name, value cnt, (sum(value) over ()) total   FROM V$SYSSTAT
    WHERE name like 'workarea exec%');
set heading off

-- PGA used by all DB processes
select 'SECTION 2: PGA USED BY CURRENT DB PROCESSES (IN MB), ORDER BY PGA_ALLOC_MEM' from dual;
select '==================================================================' || '=========================' from dual;
set heading on

break on report;
compute sum label '--> TOTAL' of pga_used_mem on report;
compute sum label '--> TOTAL' of pga_alloc_mem on report;
compute sum label '--> TOTAL' of pga_freeable_mem on report;
compute sum label '--> TOTAL' of pga_max_mem on report;

SELECT PROGRAM,
       round(PGA_USED_MEM / 1024 / 1024, 2)  pga_used_mem,
       round(PGA_ALLOC_MEM / 1024 / 1024, 2)  pga_alloc_mem,
       round(PGA_FREEABLE_MEM / 1024 / 1024, 2) pga_freeable_mem,
       round(PGA_MAX_MEM / 1024 / 1024, 2)  pga_max_mem
  FROM V$PROCESS
 order by pga_alloc_mem desc;


set heading off
select 'The columns have the following meaning:' from dual;
select '  - PGA_USED_MEM = PGA memory currently used by the process' from dual;
select '  - PGA_ALLOC_MEM = PGA memory currently allocated by the process (including free '   || 'PGA memory not yet released to the operating system by the server process)' from dual;
select '  - PGA_FREEABLE_MEM = Allocated PGA memory which can be freed' from dual;
select '  - PGA_MAX_MEM = Maximum PGA memory ever allocated by the process' from dual;
select '' from dual;

set feedback off;
select 'SECTION 3: USED PGA MEMORY BY CATHEGORIES (VALUES IN MB ORDER DESC BY ALLOCATED_MB).' from dual;
select '=================================================================='  || '=========================' from dual;
set heading on
select category,
       round(sum(allocated) / 1024 / 1024, 2) allocated_mb,
       round(sum(used) / 1024 / 1024, 2) used_mb,
       round(sum(max_allocated) / 1024 / 1024, 2) max_allocated_mb
  from v$process_memory
 group by category
 order by 2 desc;

set heading off
select '' from dual;

-- workareas histogram
select 'SECTION 4: SQL WORKAREAS HISTOGRAM' from dual;
select '==================================================================' || '=========================' from dual;
set heading on
SELECT LOW_OPTIMAL_SIZE/1024 low_kb,
       (HIGH_OPTIMAL_SIZE+1)/1024 high_kb,
       OPTIMAL_EXECUTIONS, ONEPASS_EXECUTIONS, MULTIPASSES_EXECUTIONS
  FROM V$SQL_WORKAREA_HISTOGRAM
 WHERE TOTAL_EXECUTIONS != 0;

set heading off
select '' from dual;

-- active workareas
select 'SECTION 5: CURRENTLY ACTIVE WORKAREAS' from dual;
select '==================================================================' || '=========================' from dual;
set heading on  feedback on
col OPERATION for a20
SELECT to_number(decode(SID, 65535, NULL, SID)) sid,
       operation_type OPERATION,
       trunc(EXPECTED_SIZE/1024) ESIZE,
       trunc(ACTUAL_MEM_USED/1024) MEM,
       trunc(MAX_MEM_USED/1024) "MAX MEM",
       NUMBER_PASSES PASS,
       trunc(TEMPSEG_SIZE/1024/1024) TSIZE_MB
  FROM V$SQL_WORKAREA_ACTIVE
 ORDER BY 1,2;

set heading off feedback off
select 'The meaning of the above columns is:' from dual;
select '  - SID = the active session identifier' from dual;
select '  - OPERATION = the type of the operation' from dual;
select '  - ESIZE = the expected size for the sql workarea' from dual;
select '  - MEM = Amount of PGA memory (in KB) currently allocated on behalf of this work area.' from dual;
select '  - MAX MEM = Maximum memory amount (in KB) used by this work area' from dual;
select '  - PASS = Number of passes corresponding to this work area (0 if running in OPTIMAL mode)' from dual;
select '  - TSIZE_MB = Size (in megabytes) of the temporary segment used on behalf of this work area. '  || 'This column is NULL if this work area has not (yet) spilled to disk.' from dual;
select '' from dual;

-- top 10 sql with gurmand sql areas
select 'SECTION 6: OP 10 WORK AREAS REQUIRING MOST CACHE MEMORY' from dual;
select '==================================================================' || '=========================' from dual;
set heading on linesize 200
col sql_text        for a50
col operation_type  for a20
SELECT *
  FROM (SELECT distinct s.sql_id,
                        operation_type,
                        estimated_optimal_size,
                        max_tempseg_size,
                        substr(s.SQL_TEXT, 1, 50) sql_text
          FROM V$SQL_WORKAREA a, V$SQLSTATS s
         WHERE a.SQL_ID = s.SQL_ID
         ORDER BY estimated_optimal_size)
 WHERE ROWNUM <= 10;

set heading off pagesize 300
select 'SECTION 7: SQLs WITH WORK AREAS THAT HAVE BEEN EXECUTED IN ONE OR EVEN MULTIPLE PASSES' from dual;
select '==================================================================' || '=========================' from dual;
set heading on  feedback on
col SQL_TEXT for a100
SELECT s.sql_id,sql_text, sum(ONEPASS_EXECUTIONS) onepass_cnt,  sum(MULTIPASSES_EXECUTIONS) mpass_cnt FROM V$SQL s, V$SQL_WORKAREA wa
WHERE s.address = wa.address
GROUP BY s.sql_id,sql_text
HAVING sum(ONEPASS_EXECUTIONS+MULTIPASSES_EXECUTIONS)>0
order by 3;

set feedback off heading off

select 'SECTION 8: PGA TARGET ADVCE' from dual;
select '==================================================================' || '=========================' from dual;
show parameter pga_aggregate_target
set heading on
SELECT round(PGA_TARGET_FOR_ESTIMATE/1024/1024) target_mb,
       ESTD_PGA_CACHE_HIT_PERCENTAGE cache_hit_perc,
       ESTD_OVERALLOC_COUNT
  FROM V$PGA_TARGET_ADVICE;

prompt PGA_TARGET_ADVICE
set linesize 300 pagesize 300
col PGA_TARGET_FOR_ESTIMATE   for 999,999,999,990  heading 'PGA_TARGET'
col PGA_TARGET_FACTOR    for 99.0   heading 'Factor'
col BYTES_PROCESSED    for 999,999,999,999,990 heading 'Bytes Processed'
col ESTD_EXTRA_BYTES_RW   for 999,999,999,999,990 heading 'Est. Bytes|r/w'
col ESTD_PGA_CACHE_HIT_PERCENTAGE  for 9,990   heading 'Est. PGA|hit rate'
col ESTD_OVERALLOC_COUNT   for 999,990   heading 'Est.|overalloc'
select PGA_TARGET_FOR_ESTIMATE
, PGA_TARGET_FACTOR
, BYTES_PROCESSED
, ESTD_EXTRA_BYTES_RW
, ESTD_PGA_CACHE_HIT_PERCENTAGE 
, ESTD_OVERALLOC_COUNT
from v$pga_target_advice
order by PGA_TARGET_FACTOR
/



set linesize 300 pagesize 300
col "O/1/M" format a10
col name format a20
SELECT operation, options, object_name name, trunc(bytes/1024/1024) "input(MB)",trunc(last_memory_used/1024) last_mem,
trunc(estimated_optimal_size/1024) optimal_mem, trunc(estimated_onepass_size/1024) onepass_mem, 
decode(optimal_executions, null, null, optimal_executions||'/'||onepass_executions||'/'||multipasses_executions) "O/1/M"
FROM V$SQL_PLAN p, V$SQL_WORKAREA w 
WHERE p.address=w.address(+) 
AND p.hash_value=w.hash_value(+) 
AND p.id=w.operation_id(+) 
and p.sql_id='&sql_id'
/



COL mem_component HEAD COMPONENT FOR A35

SELECT
    component mem_component
  , ROUND(current_size/1048576) cur_mb
  , ROUND(min_size/1048576)     min_mb
  , ROUND(max_size/1048576)     max_mb
  , ROUND(user_specified_size/1048576)    spec_mb
  , oper_count
  , last_oper_type last_optype
  , last_oper_mode last_opmode
  , last_oper_time last_optime
  , granule_size/1048576        gran_mb
FROM
    v$sga_dynamic_components
/





set lines 200 pages 100
col parameter          format a50
col description        format a80 word_wrapped
col "session value"    format a10
col "instance value"   format a10
select a.ksppinm       "parameter",
a.ksppdesc             "description",
b.ksppstvl             "session value",
c.ksppstvl             "instance value"
from x$ksppi a,x$ksppcv b,x$ksppsv c
where a.indx = b.indx
and a.indx = c.indx
and a.ksppinm like '/_pga%' escape '/'
order by a.ksppinm;


parameter                                          description                                                                      session va instance v
-------------------------------------------------- -------------------------------------------------------------------------------- ---------- ----------
_pga_aggregate_xmem_limit                          limit of aggregate PGA XMEM memory consumed by the instance                      0          0
_pga_auto_snapshot_percentage                      percent growth of PGA memory for additional snapshots                            20         20
_pga_auto_snapshot_threshold                       bytes of PGA memory in one process to trigger detail snapshot                    524288000  524288000
_pga_in_sga_param1                                 pga in sga param1
_pga_in_sga_param2                                 pga in sga param2
_pga_in_sga_param3                                 pga in sga param4
_pga_in_sga_param4                                 pga in sga param4
_pga_in_sga_param5                                 pga in sga param4
_pga_large_extent_size                             PGA large extent size                                                            1048576    1048576
_pga_limit_check_wait_time                         microseconds to wait for over limit confirmation                                 1000000    1000000
_pga_limit_dump_summary                            dump PGA summary when signalling ORA-4036                                        TRUE       TRUE
_pga_limit_interrupt_smaller                       whether to interrupt smaller eligible processes                                  FALSE      FALSE
_pga_limit_min_req_size                            bytes of PGA usage below which process will not get ORA-4036                     4194304    4194304
_pga_limit_per_process_minimum                     pga_aggregate_limit per-process minimum                                          3145728    3145728
_pga_limit_physmem_perc                            default percent of physical memory for pga_aggregate_limit and SGA               90         90
_pga_limit_simulated_physmem_size                  bytes of physical memory to determine pga_aggregate_limit with                   0          0
_pga_limit_target_perc                             default percent of pga_aggregate_target for pga_aggregate_limit                  200        200
_pga_limit_time_to_interrupt                       seconds to wait until direct interrupt                                           2          2
_pga_limit_time_until_idle                         seconds to wait before treating process as idle                                  15         15
_pga_limit_time_until_killed                       seconds to wait before killing session over limit                                30         30
_pga_limit_tracing                                 trace pga_aggregate_limit activity                                               0          0
_pga_limit_use_immediate_kill                      use immediate kill for sessions over limit                                       TRUE       TRUE
_pga_limit_watch_perc                              percentage of limit to have processes watch                                      50         50
_pga_limit_watch_size                              bytes of PGA usage at which process will begin watching limit                    104857600  104857600
_pga_max_size                                      Maximum size of the PGA memory for one process                                   209715200  209715200



Oracle function TRANSLATE

function TRANSLATE


select TRANSLATE('12123 3434 4535 5656','0123456789 ','0123456789') from dual
^
|
TRANSLATE('121233
-----------------
12123343445355656

in this case we have not given space translate information so it will trim space



select replace('I am vihaan','vihaan','Anuj') result from dual;

RESULT
---------
I am Anuj

Oracle Object being Access

Oracle Object being access
identify objects being accessed by sessions.
object access
Oracle access


set feed off
set pagesize 10000
set wrap off
set linesize 200;
set heading on
set tab on
set scan on
set verify off
col "Object Being Accessed" format a25
col "sid-serial" format a15
col "User" format a12
col "Owner" like "User"
col sql_text format a40
--
ttitle left 'Who uses what objects' -
skip 2

select a.sid||','||serial# "sid-serial",substr(s.username,1,10) "User",substr(a.owner,1,10) "Owner",
substr(a.object,1,30) "Object Being Accessed",s.sql_id,substr(sql_text,1,40) sql_text
from V$ACCESS a, V$SESSION s ,v$sql sq
where a.sid = s.sid
and a.owner !='SYS'
and sq.sql_id (+) = s.sql_id;




sid-serial User Owner Object Being Accessed SQL_ID SQL_TEXT
--------------- ------------ ------------ ------------------------- ------------- ----------------------------------------
13,1 PUBLIC DBA_INDEXES
41,9032 SYS PUBLIC V$PARAMETER 2h6wst2nza2wv select a.sid||','||serial# "sid-serial",
41,9032 SYS GGATE GGS_SETUP 2h6wst2nza2wv select a.sid||','||serial# "sid-serial",
13,1 PUBLIC DBA_TAB_PARTITIONS
13,1 GGATE GGS_TEMP_COLS
13,1 PUBLIC DBMS_UTILITY
13,1 PUBLIC DBMS_SESSION
13,1 GGATE GGS_SETUP
41,9032 SYS PUBLIC DBA_IND_COLUMNS 2h6wst2nza2wv select a.sid||','||serial# "sid-serial",
41,9032 SYS CTXSYS DRIERR 2h6wst2nza2wv select a.sid||','||serial# "sid-serial",
41,9032 SYS CTXSYS DR$OBJECT_ATTRIBUTE 2h6wst2nza2wv select a.sid||','||serial# "sid-serial",

Sqlplus Font size change

Change the font and font size
You can change the font in SQL*Plus for Windows NT/2000. So far, I have only managed to make this work in SQL*Plus 8.1, 9.0 and 9.2
In regedt32, go to
    HKEY_LOCAL_MACHINE
                -> SOFTWARE
                    -> ORACLE
                         -> HOME0
Create a new registry value called SQLPLUS_FONT of type REG_EXPAND_SZ and set it to your favourite fixed-width font, Eg. Courier New
Create a new registry value called SQLPLUS_FONT_SIZE of type REG_EXPAND_SZ and set it to the size you want (16 is a good size).

Oracle Index Statistics

Oracle Index analyze

change the owner



rem Script: dbb_index_stats.sql
rem Used by dbbackup.shl to create the index statistics for PROD.
set showmode off
set echo off
set heading off
set pagesize 0
set timing off
set feedback off
rem accept indexname char prompt 'Enter index name (or pattern) for statistics: '
rem accept delonly char prompt 'Only indexes with deleted rows (Y or N)? '
define indexname = %
define delonly = Y
set termout off
set linesize 80
set verify off
spool index_statsa.sql
select 'define indexname = ' || upper('&indexname') from dual;
spool off
@index_statsa.sql
spool index_statsa.sql
select 'define delrows = ' || decode('&delonly','Y',1,'y',1,0) from dual;
spool off
@index_statsa.sql
set space 0
col "Name" format a20 trunc
col "Tot Row" format 9999999
col "Tot Len" format 99999999
col "Del Row" format 9999999
col "Del Len" format 9999999
col "Del %" format 999.99
col "Ext" format 999
col " Tablspac" format a9 trunc
spool index_statsa.sql
select 'validate index ' || owner || '.' || index_name || ';' || chr(10) ||
'select rpad(name,19) "Name",''' || rpad(owner,7) || ''',lf_rows "Tot Row",' || chr(10) ||
'lf_rows_len "Tot Len",del_lf_rows "Del Row",' || chr(10) ||
'del_lf_rows_len "Del Len",decode(lf_rows_len,0,' || chr(10) ||
'decode(del_lf_rows_len,0,0.0,100.0),' || chr(10) ||
'decode(sign(del_lf_rows_len/lf_rows_len*100-100.0),1,100.0,' || chr(10) ||
'del_lf_rows_len/lf_rows_len*100)) "Del %",extents "Ext",' || chr(10) ||
''' '' || tablespace_name " Tablspac"' || chr(10) ||
'from index_stats,dba_segments where name = segment_name' || chr(10) ||
'and name = ''' || index_name || ''' and del_lf_rows >= &delrows' || chr(10) ||
'and owner = ''' || owner || ''';'
from dba_indexes where index_name like '&indexname'
and owner in ('SCOTT');
spool off
spool index_stats.lst
@index_statsa.sql
spool off
!sort -r index_stats.lst | sort +5n -r >index_statsa.lst
!echo `date` >index_stats.lst
!echo >>index_stats.lst
!echo 'Name Owner Tot Row Tot Len Del Row Del Len Del % Ext Tablspac' >>index_stats.lst
!echo '------------------- ------- ------- -------- ------- ------- ------ --- --------' >>index_stats.lst
!cat index_statsa.lst >>index_stats.lst
!rm index_statsa.sql
!rm index_statsa.lst
!/home/oracle/all_rights.shl index_stats.lst
rem !/home/oracle/view_or_print.shl index_stats.lst 'Index Statistics'
set space 1
set linesize 80
set termout on
set heading on
set pagesize 24
set timing on
set feedback 6
set verify on
set echo on
set showmode both

Oracle DBA

anuj blog Archive