Power Scripts Code Depot
Power Scripts Code Depot
------rem rem rem rem rem rem rem rem col col col col col col col col col
This script is free for non-commercial purposes with no warranties. Use at your
own risk. To license this script for a commercial purpose, contact info@rampant.
cc ************************************************* SYS_EVENTS_PCT.SQL Mike Aul
t This report shows the major events in the database and their contribution to o
verall response time. event format a30 heading 'Event Name' waits format 999,999
,999 heading 'Total|Waits' average_wait format 999,999,999 heading 'Average|Wait
s' time_waited format 999,999,999 heading 'Time Waited' total_time new_value div
ide_by noprint value new_value val
noprint percent format 999.990 heading 'Percent
|Of|Non-Idle Waits' duration new_value millisec noprint p_of_total heading 'Perc
ent|of Total|Uptime' format 999.9999
set lines 132 feedback off verify off pages 50 select to_number(sysdate-startup_
time)*86400*1000 duration from v$instance ; select sum(time_waited) total_time f
rom v$system_event where total_waits-total_timeouts>0 and event not like 'SQL*Ne
t%' and event not like 'smon%' and event not like 'pmon%' and event not like 'rd
bms%' and event not like 'PX%' and event not like 'sbt%' and event not in ('gcs
remote message','ges remote message', 'virtual circuit status','dispatcher timer
') ; select value from v$sysstat where name ='CPU used when call started' ; ttit
le 'System Events Percent' break on report compute sum of time_waited on report
spool sys_events select name event, 0 waits, 0 average_wait, value time_waited,
value/(&÷_by+&&val)*100 Percent, value/&&millisec*100 p_of_total from v$sy
sstat where name ='CPU used when call started'
event not like 'SQL*Net%' event not like 'smon%' event not like 'pmon%' event no
t like 'rdbms%' event not like '%control%' event not like 'LGWR%' and event not
like 'PX%' order by time_waited desc / spool off clear columns ttitle off
and and and and and and
--------rem rem rem rem
************************************************* Copyright 2005 by Rampant Tech
Press This script is free for non-commercial purposes with no warranties. Use at
your own risk. To license this script for a commercial purpose, contact info@ra
mpant.cc ************************************************* SEE_4031.SQL Mike Aul
t kghlurcr kghlutrn kghlufsh kghluops kghlunfu kghlunfs heading heading heading
heading heading heading "RECURRENT|CHUNKS" "TRANSIENT|CHUNKS" "FLUSHED|CHUNKS" "
PINS AND|RELEASES" "ORA-4031|ERRORS" "LAST ERROR|SIZE"
column column column column column column
ttitle 'Report on 4031 events (SYS user only)' spool cpu_stats select kghlurcr,
kghlutrn, kghlufsh, kghluops, kghlunfu, kghlunfs from sys.x$kghlu where inst_id
= userenv('Instance') ; spool off clear columns ttitle off
undef sec_snap_id
---------wt_events_int_10g.sql ************************************************* Copyrigh
t 2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk. To license this script for a commercial pu
rpose, contact [email protected] *************************************************
select event , waits "Waits" , time "Wait Time (s)" , pct*100 "Percent of Total"
, waitclass "Wait Class" from (select e.event_name event
, e.total_waits waits , (e.time_waited_micro - nvl(b.time_waited_micro,0))/100000 0 time , (e.ti
me_waited_micro - nvl(b.time_waited_micro,0))/ (select sum(e1.time_waited_micro
- nvl(b1.time_waited_mic ro,0)) from dba_hist_system_event b1 , dba_hist_system_
event e1 where b1.snap_id(+) = b.snap_id and e1.snap_id = e.snap_id
and b1.dbid
d e1.dbid = e.dbid and b1.instance_number(+) = b.instance_number and e1.instance
_number = e.instance_number and b1.event_id(+) = e1.event_id and e1.total_waits
> nvl(b1.total_waits,0) and e1.wait_class <> 'Idle' ) pct , e.wait_class waitcla
ss from dba_hist_system_event b , dba_hist_system_event e where b.snap_id(+) = &
pBgnSnap and e.snap_id = &pEndSnap and b.dbid(+) = &pDbId and e.dbid = &pDbId
and b
.instance_number(+) = &pInstNum
and e.instance_number = &pInstNum and b.event_id(+)
= e.event_id
and e.total_waits > nvl(b.total_waits,0) and e.wait_class <> 'Idle'
time desc, waits desc )
------enq_stat_int_10g.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk.
-- To license this script for a commercial purpose, -- contact [email protected] - ************************************************* select ety Enqueue , reqs "R
equests", sreq "Successful Gets", freq "Failed Gets", waits "Waits", wttm "Wait
Time (s)", awttm "Average Wait Time(ms)" from ( select /*+ ordered */ e.eq_type
|| '-' || to_char(nvl(l.name,' ')) || decode( upper(e.req_reason) , 'CONTENTION'
, null , '-', null , ' ('||e.req_reason||')') ety , e.total_req# - nvl(b.total_r
eq#,0) reqs , e.succ_req# - nvl(b.succ_req#,0) sreq , e.failed_req# - nvl(b.fail
ed_req#,0) freq , e.total_wait# - nvl(b.total_wait#,0) waits , (e.cum_wait_time
- nvl(b.cum_wait_time,0))/1000 wttm , decode( (e.total_wait# - nvl(b.total_wait#
,0)) , 0, to_number(NULL) , ( (e.cum_wait_time - nvl(b.cum_wait_time,0)) / (e.to
tal_wait# - nvl(b.total_wait#,0)) ) ) awttm from dba_hist_enqueue_stat e , dba_h
ist_enqueue_stat b , v$lock_type l where b.snap_id(+) = &pBgnSnap and e.snap_id
= &pEndSnap and b.dbid(+) = &pDbId and e.dbid = &pDbId and b.dbid(+) = e.dbid an
d b.instance_number(+) = &pInstNum and e.instance_number = &pInstNum and b.insta
nce_number(+) = e.instance_number and b.eq_type(+) = e.eq_type and b.req_reason(
+) = e.req_reason and e.total_wait# - nvl(b.total_wait#,0) > 0 and l.type(+) = e
.eq_type order by wttm desc, waits desc)
---------sys_time_model_int_10g.sql ************************************************* Cop
yright 2005 by Rampant TechPress This script is free for non-commercial purposes
with no warranties. Use at your own risk. To license this script for a commerci
al purpose, contact [email protected] ********************************************
*****
column "Statistic Name" format A40
column "Time (s)" format 999,999 column "Percent of Total DB Time" format 999,99
9 select e.stat_name "Statistic Name" , (e.value - b.value)/1000000 "Time (s)" ,
decode( e.stat_name,'DB time' , to_number(null) , 100*(e.value - b.value) )/ (
select nvl((e1.value - b1.value),-1) from dba_hist_sys_time_model e1 , dba_hist_
sys_time_model b1 where b1.snap_id = b.snap_id and e1.snap_id = e.snap_id and b1
.dbid
= b.dbid and e1.dbid = e.dbid and b1.instance_number = b.instance_number a
e_number = e.instance_number and b1.stat_name = 'DB time' and b1.stat_id = e1.sta
t_id ) "Percent of Total DB Time" from dba_hist_sys_time_model e , dba_hist_sys_
time_model b where and and and and and and and order b.snap_id e.snap_id b.dbid e.
dbid b.instance_number e.instance_number b.stat_id e.value - b.value > 0 by 2 de
sc; = = = = = = = &pBgnSnap &pEndSnap &pDbId &pDbId &pInst_Num &pInst_Num e.stat
_id
---------ash_enqueues.sql ************************************************* Copyright 200
5 by Rampant TechPress This script is free for non-commercial purposes with no w
arranties. Use at your own risk. To license this script for a commercial purpose
, contact [email protected] ************************************************* begi
n_interval_time req_reason cum_wait_time total_req# total_wait# failed_req# form
at a10 format a25 head CUM|WAIT|TIME head TOTAL|REQ# head TOTAL|WAIT# head FAILE
D|REQ#
column column column column column column
select begin_interval_time, eq_type, req_reason, total_req#,
100 * (round ((sum (decode (name, 'physical reads', value, 0)) sum (decode (name
, 'physical reads direct', value, 0)) sum (decode (name, 'physical reads direct
(lob)', value, 0))) / (sum (decode (name, 'session logical reads', value, 1)) ),
3)) hit_ratio from sys.v_$sysstat where name in ('session logical reads', 'physica
l reads direct (lob)', 'physical reads', 'physical reads direct');
---------syswaits.sql ************************************************* Copyright 2005 by
Rampant TechPress This script is free for non-commercial purposes with no warra
nties. Use at your own risk. To license this script for a commercial purpose, co
ntact [email protected] *************************************************
select event, total_waits, round(100 * (total_waits / sum_waits),2) pct_waits, t
ime_wait_sec, round(100 * (time_wait_sec / greatest(sum_time_waited,1)),2) pct_t
ime_waited, total_timeouts, round(100 * (total_timeouts / greatest(sum_timeouts,
1)),2) pct_timeouts, average_wait_sec from (select event, total_waits, round((ti
me_waited / 100),2) time_wait_sec, total_timeouts, round((average_wait / 100),2)
average_wait_sec from sys.v_$system_event where event not in ('lock element cle
anup', 'pmon timer', 'rdbms ipc message', 'rdbms ipc reply', 'smon timer',
rem NAME: fileio.sql rem rem FUNCTION: Reports on the file io status of all of t
he rem datafiles in the database. rem rem Mike Ault rem column sum_io1 new_value
st1 noprint column sum_io2 new_value st2 noprint column sum_io new_value divide
_by noprint column Percent format 999.999 heading 'Percent|Of IO' column brratio
format 999.99 heading 'Block|Read|Ratio' column bwratio format 999.99 heading '
Block|Write|Ratio' column phyrds heading 'Physical | Reads' column phywrts headi
ng 'Physical | Writes' column phyblkrd heading 'Physical|Block|Reads' column phy
blkwrt heading 'Physical|Block|Writes' column name format a30 heading 'File|Name
' column file# format 9999 heading 'File' column dt new_value today noprint TTIT
LE 'FILE I/O Status' select to_char(sysdate,'ddmonyyyyhh24miss') dt from dual; s
et feedback off verify off lines 132 pages 60 sqlbl on trims on rem select nvl(s
um(a.phyrds+a.phywrts),0) sum_io1 from sys.v_$filestat a; select nvl(sum(b.phyrd
s+b.phywrts),0) sum_io2 from sys.v_$tempstat b; select &st1+&st2 sum_io from dua
l; rem title 'File IO Statistics Report' spool fileio&&today select a.file#,b.na
me, a.phyrds, a.phywrts, (100*(a.phyrds+a.phywrts)/÷_by) Percent, a.phyblk
rd, a.phyblkwrt, (a.phyblkrd/greatest(a.phyrds,1)) brratio, (a.phyblkwrt/greates
t(a.phywrts,1)) bwratio from sys.v_$filestat a, sys.v_$dbfile b where a.file#=b.
file# union select c.file#,d.name, c.phyrds, c.phywrts, (100*(c.phyrds+c.phywrts
)/÷_by) Percent, c.phyblkrd, c.phyblkwrt,(c.phyblkrd/greatest(c.phyrds,1))
brratio, (c.phyblkwrt/greatest(c.phywrts,1)) bwratio from sys.v_$tempstat c, sy
s.v_$tempfile d where c.file#=d.file# order by 1 / spool off set feedback on ver
ify on lines 80 pages 22
column phyrds heading 'Physical | Reads' column phywrts heading 'Physical | Writ
es' column phyblkrd heading 'Physical|Block|Reads' column phyblkwrt heading 'Phy
sical|Block|Writes' column filename format a45 heading 'File|Name' column file#
format 9999 heading 'File' set feedback off verify off lines 132 pages 60 sqlbl
on trims on rem select nvl(sum(a.phyrds+a.phywrts),0) sum_io1 from stats$filesta
txs a where snap_id=&&snap; select nvl(sum(b.phyrds+b.phywrts),0) sum_io2 from s
tats$tempstatxs b where snap_id=&&snap; select &st1+&st2 sum_io from dual; rem t
title132 'Snap&&snap File IO Statistics Report' spool fileio&&snap select a.file
name, a.phyrds, a.phywrts, (100*(a.phyrds+a.phywrts)/÷_by) Percent, a.phyb
lkrd, a.phyblkwrt, (a.phyblkrd/greatest(a.phyrds,1)) brratio, (a.phyblkwrt/great
est(a.phywrts,1)) bwratio from stats$filestatxs a where a.snap_id=&&snap union s
elect c.filename, c.phyrds, c.phywrts, (100*(c.phyrds+c.phywrts)/÷_by) Per
cent, c.phyblkrd, c.phyblkwrt,(c.phyblkrd/greatest(c.phyrds,1)) brratio, (c.phyb
lkwrt/greatest(c.phywrts,1)) bwratio from stats$tempstatxs c where c.snap_id=&&s
nap order by 1 / spool off pause Press enter to continue set feedback on verify
on lines 80 pages 22 clear columns ttitle off undef snap
---------physpctio.sql ************************************************* Copyright 2005 b
y Rampant TechPress This script is free for non-commercial purposes with no warr
anties. Use at your own risk. To license this script for a commercial purpose, c
ontact [email protected] *************************************************
and d.addr = b.paddr and e.paddr (+) = b.paddr and c.name in ('physical reads',
'physical writes', 'physical writes direct', 'physical reads direct', 'physical
writes direct (lob)', 'physical reads direct (lob)', 'db block gets', 'db block
changes', 'consistent changes', 'consistent gets', 'sorts (disk)', 'sorts (memor
y)', 'sorts (rows)', 'user commits', 'user rollbacks', 'execute count' ) group b
y b.sid, d.spid, decode (b.username,null,e.name,b.username), b.machine, to_char(
logon_time,'mm/dd/yy hh:mi:ss pm') order by 6 desc;
---------DBWR_STAT.sql ************************************************* Copyright 2005 b
y Rampant TechPress This script is free for non-commercial purposes with no warr
anties. Use at your own risk. To license this script for a commercial purpose, c
ontact [email protected] *************************************************
rem rem dbwr_stat.sql rem Mike Ault rem col name format a46 heading 'DBWR Statis
tic' col stat format 9,999,999,999,999 heading 'Statistic Value' set pages 40 tt
itle 'DBWR Statistic Report' spool dbwr_stat select a.name,a.stat from (select n
ame, value stat from v$sysstat where name not like '%redo%' and name not like '%
remote%') a where (a.name like 'DBWR%' or a.name like '%buffer%' or a.name like
'%write%' or name like '%summed%') union select class name, count "value" from v
$waitstat where class='data block'
union select name||' '||to_char(block_size/1024)||' hit ratio' name, round(((1 (physical_reads / (db_block_gets + consistent_gets))) * 100),3) s tat from V$bu
ffer_pool_statistics union select name||' '||to_char(block_size/1024)||' free bu
ffer wait' name,free_buffer _wait stat from V$buffer_pool_statistics union selec
t name||' '||to_char(block_size/1024)||' buffer busy wait' name,buffer_busy _wai
t stat from V$buffer_pool_statistics union select name||' '||to_char(block_size/
1024)||' write complete wait' name,write_co mplete_wait stat from V$buffer_pool_
statistics / spool off set pages 22 ttitle off
---------10g_filehist.sql ************************************************* Copyright 200
5 by Rampant TechPress This script is free for non-commercial purposes with no w
arranties. Use at your own risk. To license this script for a commercial purpose
, contact [email protected] ************************************************* begi
n_time, end_time, a.file_id, file_name, average_read_time, average_write_time, p
hysical_reads, physical_writes, physical_block_reads, physical_block_writes
select
from sys.v_$filemetric_history a, sys.dba_data_files b where a.file_id = b.file_
id order by 1,3
-10g_filehistogram.sql -- ************************************************* -- C
opyright 2005 by Rampant TechPress -- This script is free for non-commercial pur
poses
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
**** b.file_id, file_name, singleblkrdtim_milli, singleblkrds
select
from sys. v_$file_histogram a, sys.dba_data_files b where a.file# = b.file_id or
der by 1
---------seg_top_logreads_10g.sql ************************************************* Copyr
ight 2005 by Rampant TechPress This script is free for non-commercial purposes w
ith no warranties. Use at your own risk. To license this script for a commercial
purpose, contact [email protected] **********************************************
***
select object_name "Object Name" , tablespace_name "Tablespace Name" , object_ty
pe "Object Type" , logical_reads_total "Logical Reads" , ratio "%Total" from( se
lect n.owner||'.'||n.object_name||decode(n.subobject_name,null,null,'.'||n.sub o
bject_name) object_name , n.tablespace_name , case when length(n.subobject_name)
< 11 then n.subobject_name else substr(n.subobject_name,length(n.subobject_name
)-9) end subobject_name , n.object_type , r.logical_reads_total , round(r.ratio
* 100, 2) ratio from dba_hist_seg_stat_obj n , (select * from (select e.dataobj#
, e.obj# , e.dbid , e.logical_reads_total - nvl(b.logical_reads_total, 0) log i
cal_reads_total , ratio_to_report(e.logical_reads_total - nvl(b.logical_rea ds_t
otal, 0)) over () ratio
from dba_hist_seg_stat e
break on snap_time skip 2 accept stat_name char prompt 'Enter Statistic Name: ';
accept stat_value number prompt 'Enter Statistics Threshold value: '; col snap_
time col value format a19 format 999,999,999
select to_char(begin_interval_time,'yyyy-mm-dd hh24:mi') snap_time, value from d
ba_hist_sysstat natural join dba_hist_snapshot where stat_name = '&stat_name' an
d value > &stat_value order by to_char(begin_interval_time,'yyyy-mm-dd hh24:mi')
;
---------hot_write_files_10g.sql ************************************************* Copyri
ght 2005 by Rampant TechPress This script is free for non-commercial purposes wi
th no warranties. Use at your own risk. To license this script for a commercial
purpose, contact [email protected] ***********************************************
**
prompt prompt This will identify any single file who's write I/O prompt is more
than 25% of the total write I/O of the database. prompt set pages 999 break on s
nap_time skip 2 col filename col phywrts col snap_time format a40 format 999,999
,999 format a20
select to_char(begin_interval_time,'yyyy-mm-dd hh24:mi') snap_time, filename, ph
ywrts from dba_hist_filestatxs natural join dba_hist_snapshot where phywrts > 0
to_char(begin_interval_time,'hh24') ;
---------rpt_sysstat_dy_10g.sql ************************************************* Copyrig
ht 2005 by Rampant TechPress This script is free for non-commercial purposes wit
h no warranties. Use at your own risk. To license this script for a commercial p
urpose, contact [email protected] ************************************************
*
prompt prompt This will query the dba_hist_sysstat view to display prompt averag
e values by day-of-the-week prompt set pages 999 accept stat_name char prompt 'E
nter Statistic Name: '; col snap_time col avg_value format a19 format 999,999,99
9
select to_char(begin_interval_time,'day') snap_time, avg(value) avg_value from d
ba_hist_sysstat natural join dba_hist_snapshot where stat_name = '&stat_name' gr
oup by to_char(begin_interval_time,'day') order by decode( to_char(begin_interva
l_time,'day'), 'sunday',1, 'monday',2, 'tuesday',3, 'wednesday',4, 'thursday',5,
'friday',6, 'saturday',7 ) ;
-reads_10g.sql -- ************************************************* -- Copyright
2005 by Rampant TechPress -- This script is free for non-commercial purposes
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
****
break on begin_interval_time skip 2 column phyrds format 999,999,999 column begi
n_interval_time format a25 select begin_interval_time, filename, phyrds from dba
_hist_filestatxs natural join dba_hist_snapshot;
-snapfileio_10g.sql -- ************************************************* -- Copy
right 2005 by Rampant TechPress -- This script is free for non-commercial purpos
es -- with no warranties. Use at your own risk. --- To license this script for a
commercial purpose, -- contact [email protected] -- *****************************
******************** rem rem NAME: snapfileio.sql rem FUNCTION: Reports on the f
ile io status of all of the rem FUNCTION: datafiles in the database for a single
snapshot. column column column column column column column column column column
column column sum_io1 new_value st1 noprint sum_io2 new_value st2 noprint sum_i
o new_value divide_by noprint Percent format 999.999 heading 'Percent|Of IO' brr
atio format 999.99 heading 'Block|Read|Ratio' bwratio format 999.99 heading 'Blo
ck|Write|Ratio' phyrds heading 'Physical | Reads' phywrts heading 'Physical | Wr
ites' phyblkrd heading 'Physical|Block|Reads' phyblkwrt heading 'Physical|Block|
Writes' filename format a45 heading 'File|Name' file# format 9999 heading 'File'
set feedback off verify off lines 132 pages 60 sqlbl on trims on select nvl(sum(
a.phyrds+a.phywrts),0) sum_io1 from dba_hist_filestatxs a where snap_id=&&snap;
COLUMN mode_requested FORMAT a10 COLUMN lock_id1 FORMAT a30 COLUMN lock_id2 FORM
AT a10
HEADING 'Mode|Requested' HEADING 'Lock/Cursor|ID1' HEADING 'Lock|ID2'
PROMPT 'ALL is all types or modes' ACCEPT lock PROMPT 'Enter Desired Lock Type:
' ACCEPT mode PROMPT 'Enter Lock Mode: ' SET LINES 132 PAGES 59 FEEDBACK OFF ECH
O OFF VERIFY OFF BREAK ON username ttitle 'Report on Internal Locks Mode: &mode
Type: &lock' SPOOL int_locks SELECT NVL(b.username,'SYS') username, session_id,l
ock_type,mode_held, mode_requested,lock_id1,lock_id2 FROM sys.dba_lock_internal
a, sys.v_$session b WHERE UPPER(mode_held) like UPPER('%&mode%') OR UPPER('&mode
')='ALL' AND UPPER(lock_type) like UPPER('%&lock%') OR UPPER(mode_held) like UPP
ER('%&mode%') OR UPPER('&mode')='ALL' AND UPPER('&lock')='ALL' AND a.session_id=
b.sid ORDER BY 1,2 ; SPOOL OFF PAUSE press Enter to continue SET LINES 80 PAGES
22 FEEDBACK ON VERIFY ON CLEAR COLUMNS CLEAR BREAKS UNDEF LOCK UNDEF MODE
---------Waits_file.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no war
ranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] *************************************************
REM REM Waits per Datafile report REM M. Ault 2005 REM
and e.snap_id and b.dbid(+) and e.dbid and b.instance_number(+) and e.instance_n
umber and b.event_id(+) and e.total_waits and e.wait_class order by time desc, w
aits desc
= &pEndSnap = &pDbId = &pDbId = &pInstNum = &pInstNum = e.event_id > nvl(b.total
_waits,0) <> 'Idle' )
---------wait_stat_int_10g.sql ************************************************* Copyrigh
t 2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk. To license this script for a commercial pu
rpose, contact [email protected] *************************************************
e.class "E.CLASS" e.wait_count - nvl(b.wait_count,0) "Waits" e.time
- nvl(b.time,0)
"Total Wait Time (cs)" (e.time - nvl(b.time,0)) / (e.wait_count - nvl(b.wait_cou
nt,0)) "Avg Time (cs)" dba_hist_waitstat b dba_hist_waitstat e b.snap_id = &pBgn
Snap e.snap_id = &pEndSnap b.dbid = &pDbId e.dbid = &pDbId b.dbid = e.dbid b.ins
tance_number = &pInstNum e.instance_number = &pInstNum b.instance_number = e.ins
tance_number b.class = e.class b.wait_count < e.wait_count by 3 desc, 2 desc
select , , , from ,
where and and and and and and and and and order
------This script is free for non-commercial purposes with no warranties. Use at your
own risk. To license this script for a commercial purpose, contact info@rampant.
cc ************************************************* latchname "Latch Name", nwm
isses "No Wait Misses", sleeps "Sleeps", waiter_sleeps "Waiter Sleeps" e.parent_n
ame||' '||e.where_in_code latchname e.nwfail_count - nvl(b.nwfail_count,0) nwmis
ses e.sleep_count - nvl(b.sleep_count,0) sleeps e.wtr_slp_count - nvl(b.wtr_slp_
count,0) waiter_sleeps dba_hist_latch_misses_summary b dba_hist_latch_misses_sum
mary e b.snap_id(+) = &pBgnSnap e.snap_id = &pEndSnap b.dbid(+) = &pDbId e.dbid
= &pDbId b.dbid(+) = e.dbid b.instance_number(+) = &pInstNum e.instance_number =
&pInstNum b.instance_number(+) = e.instance_number b.parent_name(+) = e.parent_
name b.where_in_code(+) = e.where_in_code e.sleep_count > nvl(b.sleep_count,0) b
y 1, 3 desc
select
From ( select , , , from , where and and and and and and and and and and )
order
TO_CHAR(h.sample_time,'Day');
---------ash_total_wait_time.sql ************************************************* Copyri
ght 2005 by Rampant TechPress This script is free for non-commercial purposes wi
th no warranties. Use at your own risk. To license this script for a commercial
purpose, contact [email protected] ***********************************************
**
select h.event "Wait Event", SUM(h.wait_time/100) "Wait Time (Sec)" from v$activ
e_session_history h, v$event_name n where h.session_state = 'ON CPU' and h.sessi
on_type = 'FOREGROUND' and h.event_id = n.EVENT_ID and to_char(h.sample_time,'HH
24') = '12' and n.wait_class <> 'Idle' group by h.event order by 2 DESC;
---------ash_file_wait_time_dy.sql ************************************************* Copy
right 2005 by Rampant TechPress This script is free for non-commercial purposes
with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
****
select f.file_name Data File , COUNT(*) Wait Number , SUM(h.time_waited) Total T
ime Waited from v$active_session_history h, dba_data_files f where h.current_fil
e# = f.file_id
select 'top physical i/o process' category, sid, username, total_user_io amt_use
d, round(100 * total_user_io/total_io,2) pct_used from (select b.sid sid, nvl(b.
username,p.name) username, sum(value) total_user_io from sys.v_$statname c, sys.
v_$sesstat a, sys.v_$session b, sys.v_$bgprocess p where a.statistic#=c.statisti
c# and p.paddr (+) = b.paddr and b.sid=a.sid and c.name in ('physical reads','ph
ysical writes', 'physical reads direct', 'physical reads direct (lob)', 'physica
l writes direct', 'physical writes direct (lob)') group by b.sid, nvl(b.username
,p.name) order by 3 desc), (select sum(value) total_io from sys.v_$statname c, s
ys.v_$sesstat a where a.statistic#=c.statistic# and c.name in ('physical reads',
'physical writes', 'physical reads direct', 'physical reads direct (lob)',
direct', 'physical writes direct (lob)')) where rownum < 2 union all select 'top
logical i/o process', sid, username, total_user_io amt_used, round(100 * total_
user_io/total_io,2) pct_used from (select b.sid sid, nvl(b.username,p.name) user
name, sum(value) total_user_io from sys.v_$statname c, sys.v_$sesstat a, sys.v_$
session b, sys.v_$bgprocess p
'physi
'db block gets', 'db block changes', 'consistent changes', 'consistent gets', 's
ession pga memory', 'session uga memory', 'parse count (total)', 'CPU used by th
is session', 'parse time cpu', 'recursive cpu usage',
'sorts (disk)', 'sorts (memor
y)', 'sorts (rows)', 'user commits', 'user rollbacks', 'execute count' ) group b
y b.sid, d.spid, decode (b.username,null,e.name,b.username), b.machine, to_char(
logon_time,'mm/dd/yy hh:mi:ss pm') order by 6 desc);
---------sesswaits.sql ************************************************* Copyright 2005 b
y Rampant TechPress This script is free for non-commercial purposes with no warr
anties. Use at your own risk. To license this script for a commercial purpose, c
ontact [email protected] ************************************************* b.sid,
decode(b.username,NULL,c.name,b.username) process_name, event, a.total_waits, ro
und((a.time_waited / 100),2) time_wait_sec,a.total_timeouts, round((average_wait
/ 100),2) average_wait_sec, round((a.max_wait / 100),2) max_wait_sec FROM sys.v
_$session_event a, sys.v_$session b, sys.v_$bgprocess c
SELECT
WHERE event NOT IN ('lock element cleanup', 'pmon timer', 'rdbms ipc message', 's
mon timer',
'smon timer', 'SQL*Net message from client', 'SQL*Net break/reset to client', 'S
QL*Net message to client', 'SQL*Net more data to client', 'dispatcher timer', 'N
ull event', 'parallel query dequeue wait', 'parallel query idle wait - Slaves',
'pipe get',
'PL/SQL lock timer', 'slave wait', 'virtual circuit status', 'WMON goes to
sleep' ) and event NOT LIKE 'DFS%' and event NOT LIKE 'KXFX%' and a.sid = b.sid
and b.paddr = c.paddr (+) order by 4 desc;
---------sesshitrate.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no wa
rranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] ************************************************* b.sid
sid, decode (b.username,null,e.name,b.username) user_name, d.spid os_id, b.mach
ine machine_name, to_char(logon_time,'mm/dd/yy hh:mi:ss pm') logon_time, 100 - 1
00 * (round ((sum (decode (c.name, 'physical reads', value, 0)) sum (decode (c.n
ame, 'physical reads direct', value, 0)) sum(decode (c.name, 'physical reads dir
ect (lob)', value, 0))) / (sum (decode (c.name, 'db block gets', value, 1)) + su
m (decode (c.name, 'consistent gets', value, 0))),3)) hit_ratio
select
from sys.v_$sesstat a,
sys.v_$session b, sys.v_$statname c,
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
**** sid, username, round(total_user_mem/1024,2) mem_used_in_kb, round(100 * tot
al_user_mem/total_mem,2) mem_percent
select
from (select b.sid sid, nvl(b.username,p.name) username, sum(value) total_user_m
em from sys.v_$statname c, sys.v_$sesstat a, sys.v_$session b, sys.v_$bgprocess
p where a.statistic#=c.statistic# and p.paddr (+) = b.paddr and b.sid=a.sid and
c.name in ('session pga memory','session uga memory') group by b.sid, nvl(b.user
name,p.name)), (select sum(value) total_mem from sys.v_$statname c, sys.v_$sesst
at a where a.statistic#=c.statistic# and c.name in ('session pga memory','sessio
n uga memory')) order by 3 desc;
---------bgact.sql ************************************************* Copyright 2005 by Ra
mpant TechPress This script is free for non-commercial purposes with no warranti
es. Use at your own risk. To license this script for a commercial purpose, conta
ct [email protected] *************************************************
select name, value from sys.v_$sysstat where
(name like '%DBWR%' or name in ('dirty buffers inspected', 'summed dirty queue l
ength', 'write requests')) or (name like '%redo%') order by 1;
---------archhist.sql ************************************************* Copyright 2005 by
Rampant TechPress This script is free for non-commercial purposes with no warra
nties. Use at your own risk. To license this script for a commercial purpose, co
ntact [email protected] *************************************************
select to_char(completion_time,'mm/dd/yy') completion_time, count(*) log_count f
rom sys.v_$archived_log where sysdate - completion_time < 31 group by to_char(co
mpletion_time,'mm/dd/yy') order by 1 desc;
-rolldet.sql -- ************************************************* -- Copyright 2
005 by Rampant TechPress -- This script is free for non-commercial purposes -- w
ith no warranties. Use at your own risk. --- To license this script for a commer
cial purpose, -- contact [email protected] -- ************************************
************* select name, round ((rssize / 1024), 2) size_kb, shrinks, extends,
gets, waits, writes, xacts, status,
-------Copyright 2005 by Rampant TechPress This script is free for non-commercial purpo
ses with no warranties. Use at your own risk. To license this script for a comme
rcial purpose, contact [email protected] *****************************************
******** count(*)
select from sys.tab$ where chncnt > 0;
---------chainpct.sql ************************************************* Copyright 2005 by
Rampant TechPress This script is free for non-commercial purposes with no warra
nties. Use at your own risk. To license this script for a commercial purpose, co
ntact [email protected] *************************************************
select round(100 * (chained_row_fetches / total_fetches),2) pct_chain_access fro
m (select value as chained_row_fetches from sys.v_$sysstat a where name = 'table
fetch continued row'), (select sum(value) as total_fetches from sys.v_$sysstat
where name in ('table fetch by rowid', 'table scan rows gotten'));
----------chaintables.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no wa
rranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] ************************************************* chain
ed_rows.sql
-- FUNCTION: Show percentage of chained rows -- tables must have been analyzed - MRA -column "Chain Percent" format 999.99 column table_name heading 'Table|Nam
e' column chain_cnt heading 'Chained|Rows' column num_rows heading 'Row|Count' s
et pages 47 set feedback off ttitle 'Chained Rows Report' spool chained_rows sel
ect table_name,chain_cnt, num_rows, chain_cnt/num_rows*100 "Chain Percent" fr om
dba_tables where chain_cnt>1 and owner not in ('SYS','SYSTEM'); spool off ttitl
e off
---------maxext8.sql ************************************************* Copyright 2005 by
Rampant TechPress This script is free for non-commercial purposes with no warran
ties. Use at your own risk. To license this script for a commercial purpose, con
tact [email protected] ************************************************* owner, de
code(partition_name,NULL,segment_name,segment_name || '.' || partition_name) seg
ment_name, segment_type, extents, max_extents, initial_extent, next_extent, tabl
espace_name
select
from sys.dba_segments where max_extents - extents <= 5 and segment_type <> 'CACH
E' order by 1,2,3;
-objdef.sql -- *************************************************
-------Copyright 2005 by Rampant TechPress This script is free for non-commercial purpo
ses with no warranties. Use at your own risk. To license this script for a comme
rcial purpose, contact [email protected] *****************************************
********
select a.owner, a.segment_name, a.segment_type, a.tablespace_name, a.next_extent
, max(c.bytes) max_contig_space from sys.dba_segments a, sys.dba_free_space c wh
ere a.tablespace_name = c.tablespace_name and a.next_extent > (select max(bytes)
from sys.dba_free_space b where a.tablespace_name = b.tablespace_name and b.tab
lespace_name = c.tablespace_name) group by a.owner, a.segment_name, a.tablespace
_name, a.segment_type, a.next_extent
---------tabreorg8.sql ************************************************* Copyright 2005 b
y Rampant TechPress This script is free for non-commercial purposes with no warr
anties. Use at your own risk. To license this script for a commercial purpose, c
ontact [email protected] ************************************************* /*+ RUL
E */ owner, segment_name table_name, segment_type, round(bytes/1024,2) table_kb,
num_rows, blocks, empty_blocks, hwm highwater_mark, avg_used_blocks,
select
-------Copyright 2005 by Rampant TechPress This script is free for non-commercial purpo
ses with no warranties. Use at your own risk. To license this script for a comme
rcial purpose, contact [email protected] *****************************************
********
select table_owner "table owner", table_name "table name", command "command issu
ed", 0 - executions "executions", disk_reads "disk reads", gets "buffer gets", r
ows_processed "rows processed" from (select distinct executions, command, table_
owner, table_name,
gets, rows_processed, disk_reads from (select decode (a.command
, 'insert ' , 3,'select ', 6, 'update ' , 7, 'delete ' , 26,'table lock ') comma
nd , c.owner table_owner, c.name table_name , sum(a.disk_reads) disk_reads , sum
(0 - a.executions) executions , sum(a.buffer_gets) gets , sum(a.rows_processed)
rows_processed from sys.v_$sql a , sys.v_$object_dependency b , sys.v_$db_object_
cache c where a.command_type in (2,3,6,7,26)and b.from_address = a.address and b.
to_owner = c.owner and b.to_name= c.name and c.type = 'table' and c.owner not in
('SYS','SYSTEM') group by a.command_type , c.owner , c.name ) ) where rownum <=
100;
-largescan9i.sql
break on c1 skip 2 break on c2 skip 2 select to_char(sn.begin_interval_time,'mmdd hh24') c0, p.object_owner c1, p.object_type c2, p.object_name c3, avg(p.cpu_c
ost) c4, avg(p.io_cost)
c5 from dba_hist_sql_plan p, dba_hist_sqlstat st, db
ere p.object_name is not null and p.object_owner <> 'SYS' and p.object_name = 'C
USTOMER_DETS' and p.sql_id = st.sql_id and st.snap_id = sn.snap_id group by to_c
har(sn.begin_interval_time,'mm-dd hh24'), p.object_owner, p.object_type, p.objec
t_name order by 1,2,3 desc ;
---------awr_nested_join_alert.sql ************************************************* Copy
right 2005 by Rampant TechPress This script is free for non-commercial purposes
with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
**** c1 c2 c3 c4 c5 heading heading heading heading heading Date Nested|Loops|Co
unt Rows|Processed Disk|Reads CPU|Time format format format format format a20 99
,999,999 99,999,999 99,999,999 99,999,999
col col col col col
accept nested_thr char prompt Enter Nested Join Threshold: ttitle Nested Join Th
reshold|&nested_thr
select to_char(sn.begin_interval_time,'yy-mm-dd hh24') c1, count(*) c2, sum(st.r
ows_processed_delta)
c3, sum(st.disk_reads_delta) c4, sum(st.cpu_time_delta)
apshot sn, dba_hist_sql_plan p, dba_hist_sqlstat st where st.sql_id = p.sql_id a
nd sn.snap_id = st.snap_id and p.operation = NESTED LOOPS having count(*) > &has
h_thr group by begin_interval_time;
---------awr_sql_index.sql ************************************************* Copyright 20
05 by Rampant TechPress This script is free for non-commercial purposes with no
warranties. Use at your own risk. To license this script for a commercial purpos
e, contact [email protected] *************************************************
col c0 heading Begin|Interval|time format a8 col c1 heading Index|Name format a2
0 col c2 heading Disk|Reads format 99,999,999 col c3 heading Rows|Processed form
at 99,999,999 select to_char(s.begin_interval_time,'mm-dd hh24') c0, p.object_na
me
c1, sum(t.disk_reads_total) c2, sum(t.rows_processed_total) c3 from dba_hist_sql
_plan p, dba_hist_sqlstat t, dba_hist_snapshot s where p.sql_id = t.sql_id and t
.snap_id = s.snap_id and
where p.object_owner <> 'SYS' and p.operation like '%INDEX%' and p.options like
'%UNIQUE%' and p.sql_id = s.sql_id and s.snap_id = sn.snap_id group by to_char(s
n.begin_interval_time,'yy-mm-dd hh24') order by 1 ) u, ( select to_char(sn.begin
_interval_time,'yy-mm-dd hh24') c1, count(1) c2 from dba_hist_sql_plan p, dba_hi
st_sqlstat s, dba_hist_snapshot sn where p.object_owner <> 'SYS' and p.operation
like '%INDEX%' and p.options like '%FULL%' and p.sql_id = s.sql_id and s.snap_i
d = sn.snap_id group by to_char(sn.begin_interval_time,'yy-mm-dd hh24') order by
1 ) f where r.c1 = u.c1 and r.c1 = f.c1 ;
---------awr_sql_object_avg_dy.sql ************************************************* Copy
right 2005 by Rampant TechPress This script is free for non-commercial purposes
with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
**** format a30 format a15 format 99,999,999
col c1 heading Object|Name col c2 heading Week Day col c3 heading Invocation|Cou
nt
order by 1,2,3;
---------awr_sql_full_scans.sql ************************************************* Copyrig
ht 2005 by Rampant TechPress This script is free for non-commercial purposes wit
h no warranties. Use at your own risk. To license this script for a commercial p
urpose, contact [email protected] ************************************************
*
p.operation like '%TABLE ACCESS%' and p.options = 'FULL' and p.sql_id = s.sql_id
and s.snap_id = sn.snap_id group by to_char(sn.begin_interval_time,'yy-mm-dd hh
24') order by 1 ) f where i.c1 = f.c1 ;
---------awr_full_table_scans.sql ************************************************* Copyr
ight 2005 by Rampant TechPress This script is free for non-commercial purposes w
ith no warranties. Use at your own risk. To license this script for a commercial
purpose, contact [email protected] **********************************************
***
ttile Large Full-table scans|Per Snapshot Period col c1 heading Begin|Interval|t
ime col c4 heading FTS|Count break on c1 skip 2 break on c2 skip 2 select to_cha
r(sn.begin_interval_time,'yy-mm-dd hh24') c1, count(1) c4 from dba_hist_sql_plan
p, dba_hist_sqlstat s, dba_hist_snapshot sn, dba_segments o where p.object_owner
<> 'SYS' and p.object_owner = o.owner and p.object_name = o.segment_name and o.
blocks > 1000 and p.operation like '%TABLE ACCESS%' and p.options like '%FULL%'
and p.sql_id = s.sql_id format a20 format 999,999
-- To license this script for a commercial purpose, -- contact [email protected] - ************************************************* col col col col c1 c2 c3 c4
heading heading heading heading Begin|Interval|Time
format Large|Table|Full Table|Sca
format Small|Table|Full Table|Scans format Total|Index|Scans
format a20 999,999 99
,999
select f.c1 c1, f.c2 c2, s.c2 c3, i.c2 c4 from ( select to_char(sn.begin_interva
l_time,'yy-mm-dd hh24') c1, count(1) c2 from dba_hist_sql_plan p, dba_hist_sqlst
at s, dba_hist_snapshot sn, dba_segments o where p.object_owner <> 'SYS' and p.o
bject_owner = o.owner and p.object_name = o.segment_name and o.blocks > 1000 and
p.operation like '%TABLE ACCESS%' and p.options like '%FULL%' and p.sql_id = s.
sql_id and s.snap_id = sn.snap_id group by to_char(sn.begin_interval_time,'yy-mm
-dd hh24') order by 1 ) f, ( select to_char(sn.begin_interval_time,'yy-mm-dd hh2
4') c1, count(1)
c2 from dba_hist_sql_plan p, dba_hist_sqlstat s, d
re p.object_owner <> 'SYS' and p.object_owner = o.owner and p.object_name = o.se
gment_name
and o.blocks < 1000 and p.operation like '%INDEX%' and p.sql_id = s.sql_id and s
.snap_id = sn.snap_id group by to_char(sn.begin_interval_time,'yy-mm-dd hh24') o
rder by 1 ) s, ( select to_char(sn.begin_interval_time,'yy-mm-dd hh24') c1, coun
t(1)
c2 from dba_hist_sql_plan p, dba_hist_sqlstat s, dba_hist_snapshot sn
'SYS' and p.operation like '%INDEX%' and p.sql_id = s.sql_id and s.snap_id = sn
.snap_id group by to_char(sn.begin_interval_time,'yy-mm-dd hh24') order by 1 ) i
where f.c1 = s.c1 and f.c1 = i.c1 ;
---------awr_sql_full_scans_avg_dy.sql *************************************************
Copyright 2005 by Rampant TechPress This script is free for non-commercial purpo
ses with no warranties. Use at your own risk. To license this script for a comme
rcial purpose, contact [email protected] *****************************************
********
format a20 col c1 heading Begin|Interval|Time col c2 heading Index|Table|Scans f
ormat 999,999 col c3 heading Full|Table|Scans format 999,999 select i.c1 c1, i.c
2 c2, f.c2 c3
(round ((sum (decode (name, 'physical reads', value, 0)) sum (decode (name, 'phy
sical reads direct', value, 0)) sum (decode (name, 'physical reads direct (lob)'
, value, 0))) / (sum (decode (name, 'session logical reads', value, 1))),3)) buf
fer_hit_ratio from sys.v_$sysstat where name in ('session logical reads', 'physica
l reads direct (lob)', 'physical reads', 'physical reads direct')), (select roun
d (100 * (free_bytes / shared_pool_size), 2) percent_shared_pool_free from (sele
ct sum (bytes) free_bytes from sys.v_$sgastat where name = 'free memory' and poo
l = 'shared pool'), (select value shared_pool_size from sys.v_$parameter where n
ame = 'shared_pool_size')), (select 100 - round ((sum (reloads) / sum (pins)) *
100, 2) lib_cache_hit_ratio from sys.v_$librarycache), (select 100 - round ((sum
(getmisses) / (sum (gets) + sum (getmisses)) * 100), 2) dd_cache_hit_ratio from
sys.v_$rowcache), (select round ( (100 * b.value) / decode ((a.value + b.value)
, 0, 1, (a.value + b.value)),
2)mem_sort_ratio from v$sysstat a, v$sysstat b where a.n
me = 'sorts (disk)' and b.name = 'sorts (memory)'), (select round(100 * (sum (sy
s.v_$latch.misses) / sum (sys.v_$latch.gets)),2) latch_miss_ratio from sys.v_$latc
h), (select round (100 * (a.value - b.value) / decode (a.value, 0, 1, a.value),
2) parse_execute_ratio from sys.v_$sysstat a, sys.v_$sysstat b
where a.name = 'execute count' and b.name = 'parse count (hard)'), (select nvl(su
m(total_waits),0) buffer_busy_waits from sys.v_$system_event a, sys.v_$event_nam
e b where a.event = 'buffer busy waits' and a.event (+) = b.name), (select sum(r
eloads) object_reloads from sys.v_$librarycache), (select value redo_log_space_w
aits from sys.v_$sysstat where name = 'redo log space requests'), (select value
redo_log_space_wait_time from sys.v_$sysstat where name = 'redo log space wait t
ime');
---------poolhit.sql ************************************************* Copyright 2005 by
Rampant TechPress This script is free for non-commercial purposes with no warran
ties. Use at your own risk. To license this script for a commercial purpose, con
tact [email protected] ************************************************* name, 100
* (1 - (physical_reads / (db_block_gets + consistent_gets))) hit_ratio
select
from
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
**** size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_ph
ysical_reads
select
from sys.v_$db_cache_advice where name = 'DEFAULT'and block_size = (select value
from sys.v_$parameter
where name = 'db_block_size') and advice_status = 'ON';
---------cacheobjcnt.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no wa
rranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] ************************************************* decod
e(cachehint, 0, 'default', 1, 'keep', 2, 'recycle', null) cache, count(*) object
s
select
from sys.seg$ s where s.user# in (select user# from sys.user$ where name not in
('sys','system')) group by decode(cachehint, 0, 'default', 1, 'keep', 2, 'recycl
e', null) order by 1;
column mem_sum
format 999,999,999
heading Mem|Sum
ttitle "Users SQL Area Memory Use" spool sqlsum set pages 59 lines 80 break on r
eport compute compute compute compute sum sum sum sum of of of of sharable on re
port persistent on report runtime on report mem_sum on report
select username, sum(sharable_mem) Sharable, sum( persistent_mem) Persistent, su
m( runtime_mem) Runtime , count(*) Areas, sum(sharable_mem+persistent_mem+runtim
e_mem) Mem_sum from sql_summary group by username order by 2; spool off pause Pr
ess enter to continue clear columns clear breaks set pages 22 lines 80 ttitle of
f
-sqlmem.sql -- ************************************************* -- Copyright 20
05 by Rampant TechPress -- This script is free for non-commercial purposes -- wi
th no warranties. Use at your own risk. --- To license this script for a commerc
ial purpose, -- contact [email protected] -- *************************************
************ column sql_text format a60 heading Text word_wrapped column sharabl
e_mem heading Shared|Bytes column persistent_mem
heading Persistent|Bytes column loa
ds heading Loads column users format a15 heading "User" column executions headin
g "Executions" column users_executing heading "Used By" ttitle "Users SQL Area M
emory Use" spool sqlmem set long 2000 pages 59 lines 132 break on users compute
sum of sharable_mem on users compute sum of persistent_mem on users compute sum
of runtime_mem on users
where a.users=b.users and a.garbage is not null and b.good is not null union sel
ect 2 nopr, '-------------' users, '--------------' garbage, '--------------' go
od, '--------------' good_percent from dual union select 3 nopr, to_char(count(a
.users)) users, to_char(sum(a.garbage),'9,999,999,999') garbage, to_char(sum(b.g
ood),'9,999,999,999') good, to_char(((sum(b.good)/(sum(b.good)+sum(a.garbage)))*
100), '9,999,999.999') good_percent from sql_garbage a, sql_garbage b where a.us
ers=b.users and a.garbage is not null and b.good is not null order by 1,3 desc /
spool off
---------similar_sql.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no wa
rranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] *************************************************
set lines 140 pages 55 verify off feedback off col num_of_times heading 'Number|
Of|Repeats' col SQL heading 'SubString width - &&chars Characters' col username
format a15 heading 'User' ttitle 'Similar SQL' spool similar_sql&&chars select b
.username,substr(a.sql_text,1,&&chars) SQL, count(a.sql_text) num_of_tim es from
v$sqlarea a, dba_users b where a.parsing_user_id=b.user_id group by b.username,
substr(a.sql_text,1,&&chars) having count(a.sql_text)>&&num_ repeats order by co
unt(a.sql_text) desc / spool off undef chars undef num_repeats clear columns set
lines 80 pages 22 verify on feedback on ttitle off
-Flush_it_proc.sql
-BEGIN OPEN get_share; OPEN get_var; FETCH get_share INTO share_mem; FETCH get_var I
NTO variable_mem; mem_ratio:=share_mem/variable_mem; IF mem_ratio>p_free/100 THEN - - Following keep sections from Steve Adams nice_flush - BEGIN OPEN reused_cursors;
LOOP FETCH reused_cursors INTO cursor_string; EXIT WHEN reused_cursors%notfound;
sys.dbms_shared_pool.keep(cursor_string, 'C'); END LOOP; END; BEGIN OPEN cached_s
equences; LOOP FETCH cached_sequences INTO sequence_owner, sequence_name; EXIT W
HEN cached_sequences%notfound; sys.dbms_shared_pool.keep(sequence_owner || '.' |
| sequence_name, 'Q'); END LOOP; END; BEGIN OPEN candidate_objects; LOOP FETCH cand
idate_objects INTO object_name, object_type; EXIT WHEN candidate_objects%notfoun
d; sys.dbms_shared_pool.keep('SYS.' || object_name, object_type); END LOOP; END; - - end of Steve Adams section -cur:=DBMS_SQL.OPEN_CURSOR; sql_com:='ALTER SYSTEM F
LUSH SHARED_POOL'; DBMS_SQL.PARSE(cur,sql_com,dbms_sql.v7); row_proc:=DBMS_SQL.E
XECUTE(cur); DBMS_SQL.CLOSE_CURSOR(cur); OPEN get_time; FETCH get_time INTO toda
ys_date; INSERT INTO dba_running_stats VALUES ( 'Flush of Shared Pool',1,35,toda
ys_date,0 ); COMMIT; END IF; END flush_it;
-Gen_keep.sql
-- *************************************************
-------Copyright 2005 by Rampant TechPress This script is free for non-commercial purpo
ses with no warranties. Use at your own risk. To license this script for a commer
cial purpose, contact [email protected] ******************************************
*******
set lines 132 feedback off verify off set pages 0 spool keep_them.sql select 'ex
ecute dbms_shared_pool.keep('||chr(39)||OWNER||'.'||name||chr(39)||', '|| chr(39
)|| decode(type,'PACKAGE','P','PROCEDURE','P','FUNCTION','P','SEQUENCE','Q', 'TR
IGGER','R')||chr(39)||')' from v$db_object_cache where type not in ('NOT LOADED','
NON-EXISTENT','VIEW','TABLE', 'INVALID TYPE','CURSOR','PACKAGE BODY') and executi
ons>loads and executions>1 and kept='NO' order by owner,namespace,type,execution
s desc / spool off
---------keep_them.sql ************************************************* Copyright 2005 b
y Rampant TechPress This script is free for non-commercial purposes with no warr
anties. Use at your own risk. To license this script for a commercial purpose, c
ontact [email protected] ************************************************* dbms_sh
ared_pool.keep('APPS.WF_PARAMETER_T','') dbms_shared_pool.keep('APPS.WF_EVENT_T'
,'') dbms_shared_pool.keep('APPS.WF_AGENT_T','') dbms_shared_pool.keep('APPS.BOS
S_GET_EMP_NAME','P') dbms_shared_pool.keep('APPS.BEN_PEN_BUS','P') dbms_shared_p
ool.keep('APPS.PAY_ELE_SHD','P') dbms_shared_pool.keep('APPS.PSB_HR_POPULATE_DAT
A_PVT','P') dbms_shared_pool.keep('APPS.BEN_ENROLLMENT_ACTION_ITEMS','P') dbms_s
hared_pool.keep('APPS.FND_REQUEST_SET','P') dbms_shared_pool.keep('APPS.BOSS_REC
EIPT','P') dbms_shared_pool.keep('APPS.BEN_ELIG_DPNT_WHO','R') dbms_shared_pool.
keep('APPS.BEN_ELIG_PER_ELCTBL_CHC_WHO','R') dbms_shared_pool.keep('APPS.BEN_ELI
G_PER_OPT_F_WHO','R') dbms_shared_pool.keep('APPS.GHR_PAY_ELEMENT_ENTVAL_F_AFIUD
','R') dbms_shared_pool.keep('APPS.BEN_ENRT_RT_WHO','R') dbms_shared_pool.keep('
APPS.BEN_ELIG_PER_F_WHO','R')
execute execute execute execute execute execute execute execute execute execute
execute execute execute execute execute execute
-- To license this script for a commercial purpose, -- contact [email protected] - ************************************************* select to_char(end_time, 'YY
YY-MON-DD HH:MI:SS') end_time, value, metric_unit from sys.v_$sysmetric_history
where metric_name = 'Library Cache Hit Ratio' order by 1
---------lib_cache_int_10g.sql ************************************************* Copyrigh
t 2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk. To license this script for a commercial pu
rpose, contact [email protected] *************************************************
select b.namespace "Name Space" , e.gets - b.gets "Get Requests" , to_number(dec
ode(e.gets,b.gets,null, 100 - (e.gethits - b.gethits) * 100/(e.gets - b.gets)))
"Get Pct Miss" , e.pins - b.pins "Pin Requests" , to_number(decode(e.pins,b.pins
,null, 100 - (e.pinhits - b.pinhits) * 100/(e.pins - b.pins))) "Pin Pct Miss" ,
e.reloads - b.reloads "Reloads" , e.invalidations - b.invalidations "Invalidatio
ns" from dba_hist_librarycache b , dba_hist_librarycache e where b.snap_id = &pBg
nSnap and e.snap_id = &pEndSnap and b.dbid = &pDbId and e.dbid = &pDbId and b.db
id = e.dbid and b.instance_number = &pInstNum and e.instance_number = &pInstNum
and b.instance_number = e.instance_number and b.namespace = e.namespace
----rowcache_int_10g.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk.
, wcwait "Write Complete Waits" , poolhr "Pool Hit %" From (select e.name , e.se
t_msize numbufs , decode( e.db_block_gets - nvl(b.db_block_gets,0) + e.consistent
_gets - nvl(b.consistent_gets,0) , 0, to_number(null) , (100* (1 - ( (e.physical
_reads - nvl(b.physical_reads,0))
/ ( e.db_block_gets - nvl(b.db_block_gets,0)
ets - nvl(b.consistent_gets,0)) ) ) ) )
poolhr , e.db_block_gets - nvl(b.d
stent_gets - nvl(b.consistent_gets,0) buffs , e.consistent_gets - nvl(b.consiste
nt_gets,0) conget , e.physical_reads - nvl(b.physical_reads,0) phread , e.physic
al_writes - nvl(b.physical_writes,0) phwrite , e.free_buffer_wait - nvl(b.free_b
uffer_wait,0) fbwait , e.write_complete_wait - nvl(b.write_complete_wait,0) wcwa
it , e.buffer_busy_wait - nvl(b.buffer_busy_wait,0) bbwait from dba_hist_buffer_
pool_stat b , dba_hist_buffer_pool_stat e where b.snap_id(+) = &pBgnSnap and e.sn
ap_id = &pEndSnap and b.dbid(+) = &pDbId and e.dbid
= &pDbId and b.dbid(+) = e.dbi
nstance_number(+) = &pInst_Num and e.instance_number = &pInst_Num and b.instance
_number(+) = e.instance_number and b.id(+) = e.id) order by 1
---------rpt_10g_lib_miss.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk. To license this script for a commercial pur
pose, contact [email protected] *************************************************
set lines 80; set pages 999; column column column column mydate heading 'Yr. Mo
Dy Hr.' format a16 c1 heading "execs" format 9,999,999 c2 heading "Cache Misses|
While Executing" format 9,999,999 c3 heading "Library Cache|Miss Ratio" format 9
99.99999
break on mydate skip 2;
and t.buffer_pool <> 'KEEP' having s.blocks < 50 group by p.owner, p.name, t.num
_rows, s.blocks UNION -- *******************************************************
**** -- Next, get the index names -- *******************************************
**************** select 'alter index '||owner||'.'||index_name||' storage (buffe
r_pool keep);' from dba_indexes where owner||'.'||table_name in ( select p.owner
||'.'||p.name from dba_tables t, dba_segments s, dba_hist_sqlstat a, (select distin
ct pl.sql_id, pl.object_owner owner, pl.object_name name from dba_hist_sql_plan
pl where pl.operation = 'TABLE ACCESS' and pl.options = 'FULL') p where a.sql_id
= p.sql_id and t.owner = s.owner and t.table_name = s.segment_name and t.table_
name = p.name and t.owner = p.owner and t.owner not in ('SYS','SYSTEM') and t.bu
ffer_pool <> 'KEEP' having s.blocks < 50 group by p.owner, p.name, t.num_rows, s
.blocks )
-high_sql_buf_gets.sql -- ************************************************* -- Co
pyright 2005 by Rampant TechPress -- This script is free for non-commercial purp
oses -- with no warranties. Use at your own risk. --- To license this script for
a commercial purpose, -- contact [email protected] -- ***************************
********************** select sql_id , buffer_gets_total "Buffer Gets" , executi
ons_total "Executions" , buffer_gets_total/executions_total "Gets / Exec" , pct*
100 "% Total" , cpu_time_total/1000000 "CPU Time (s)" , elapsed_time_total/10000
00 "Elapsed Time (s)" , module "SQL Module" , stmt "SQL Statement" from (select
e.sql_id sql_id , e.buffer_gets_total - nvl(b.buffer_gets_total,0) buffer_gets_t
ot al , e.executions_total - nvl(b.executions_total,0) executions_total , (e.buf
fer_gets_total - nvl(b.buffer_gets_total,0))/ ( select e1.value - nvl(b1.value,0
) from dba_hist_sysstat b1 , dba_hist_sysstat e1 where b1.snap_id(+) = b.snap_id a
nd e1.snap_id = e.snap_id and b1.dbid(+) = b.dbid
and e1.dbid = e.dbid and b1.inst
er(+) = b.instance_number and e1.instance_number = e.instance_number and b1.stat
_id = e1.stat_id and e1.stat_name = 'session logical reads' ) pct , e.elapsed_ti
me_total - nvl(b.elapsed_time_total,0) elapsed_time_ total , e.cpu_time_total nvl(b.cpu_time_total,0) cpu_time_total
, e.module , t.sql_text stmt from dba_hist_sqls
tat e , dba_hist_sqlstat b , dba_hist_sqltext t where b.snap_id(+) = @pBgnSnap a
nd b.dbid(+) = e.dbid and b.instance_number(+) = e.instance_number and b.sql_id(
+) = e.sql_id and e.snap_id = &pEndSnap and e.dbid = &pDBId and e.instance_numbe
r = &pInstNum and (e.executions_total - nvl(b.executions_total,0)) > 0 and t.sql
_id = b.sql_id )
order by 2 desc
---------top_sql_waits.sql ************************************************* Copyright 20
05 by Rampant TechPress This script is free for non-commercial purposes with no
warranties. Use at your own risk. To license this script for a commercial purpos
e, contact [email protected] *************************************************
select ash.user_id, u.username, sqla.sql_text, sum(ash.wait_time + ash.time_wait
ed) wait_time from v$active_session_history ash, v$sqlarea sqla, dba_users u whe
re ash.sample_time > sysdate-1 and ash.sql_id = sqla.sql_id and ash.user_id = u.
user_id group by ash.user_id, sqla.sql_text, u.username order by 4;
---------obj_wait_ash.sql ************************************************* Copyright 200
5 by Rampant TechPress This script is free for non-commercial purposes with no w
arranties. Use at your own risk. To license this script for a commercial purpose
, contact [email protected] *************************************************
select obj.object_name, obj.object_type, ash.event, sum(ash.wait_time + ash.time
_waited) wait_time from v$active_session_history ash,
ttitle
time series execution for|&sqlid
break on c1 select to_char(s.begin_interval_time, mm-dd hh24 ) c1, sql.execution
s_delta c2, sql.buffer_gets_delta c3, sql.disk_reads_delta c4, sql.iowait_delta
c5, sql.apwait_delta c6, sql.ccwait_delta c7, sql.cpu_time_delta c8, sql.elapsed
_time_delta c9 from dba_hist_sqlstat sql, dba_hist_snapshot s where s.snap_id = s
ql.snap_id and sql_id = &sqlid order by c1 ;
---------awr_high_cost_sql.sql ************************************************* Copyrigh
t 2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk. To license this script for a commercial pu
rpose, contact [email protected] *************************************************
format a13 format 9,999,999 format a200
col c1 heading SQL|ID col c2 heading Cost col c3 heading SQL Text select p.sql_i
d c1, p.cost c2, to_char(s.sql_text) c3 from dba_hist_sql_plan p, dba_hist_sqlte
xt s where p.id = 0 and p.sql_id = s.sql_id and p.cost is not null
column owner format a9; column table_name format a20; column index_name format a
20; ttitle 'Index full scans and counts' select to_char(sn.end_interval_time,'mm
/dd/rr hh24') time, p.owner, d.table_name, p.name index_name, seg.blocks tbl_blo
cks, sum(s.executions_delta) nbr_scans from dba_segments seg, dba_indexes d, dba
_hist_sqlstat s, dba_hist_snapshot sn, (select distinct pl.sql_id, object_owner
owner, object_name name from dba_hist_sql_plan pl where operation = 'INDEX' and
options = 'FULL SCAN') p where d.index_name = p.name and s.snap_id = sn.snap_id
and s.sql_id = p.sql_id and d.table_name = seg.segment_name and seg.owner = p.ow
ner having sum(s.executions_delta) > 9 group by to_char(sn.end_interval_time,'mm
/dd/rr hh24'),p.owner, d.table_name, p.name, seg.blocks order by 1 asc; ttitle '
Index range scans and counts' select to_char(sn.end_interval_time,'mm/dd/rr hh24
') time, p.owner, d.table_name, p.name index_name, seg.blocks tbl_blocks, sum(s.
executions_delta) nbr_scans from dba_segments seg, dba_hist_sqlstat s, dba_hist_
snapshot sn, dba_indexes d, (select distinct
spool off
---------spacesum8i.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no war
ranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] *************************************************
select tablespace_name, autoextend, round ((total_space / 1024 / 1024), 2) as to
tal_space, round ((total_free_space / 1024 / 1024), 2) as total_free, round (((t
otal_space - total_free_space) / 1024 / 1024), 2) as used_space, to_char ( nvl (
round ( (100 * sum_free_blocks / sum_alloc_blocks),2),0)) || '%' as pct_free fro
m (select tablespace_name, max (autoextensible) autoextend,
sum (blocks) sum_alloc_
blocks, sum (bytes) as total_space from dba_data_files group by tablespace_name)
, (select b.tablespace_name fs_ts_name, nvl (sum (bytes), 0) as total_free_space
, sum (blocks) as sum_free_blocks from dba_free_space a, dba_tablespaces b where
a.tablespace_name (+) = b.tablespace_name group by b.tablespace_name, status) wh
ere tablespace_name = fs_ts_name union all select d.tablespace_name, autoextend,
round ((a.bytes / 1024 / 1024), 2), round ((a.bytes / 1024 / 1024) (nvl (t.byte
s, 0) / 1024 / 1024), 2),
round (nvl (t.bytes, 0) / 1024 / 1024, 2), to_char (100 - (nvl (t.bytes / a.byte
s * 100, 0)), '990.00') from sys.dba_tablespaces d, (select tablespace_name, max
(autoextensible) autoextend, sum (bytes) bytes from dba_temp_files group by tab
lespace_name) a, (select tablespace_name, sum (bytes_cached) bytes from sys.v_$t
emp_extent_pool group by tablespace_name) t where and and and order d.tablespace_n
ame = a.tablespace_name (+) d.tablespace_name = t.tablespace_name (+) d.extent_m
anagement like 'LOCAL' d.contents like 'TEMPORARY' by 1;
---------datafileae.sql ************************************************* Copyright 2005
by Rampant TechPress This script is free for non-commercial purposes with no war
ranties. Use at your own risk. To license this script for a commercial purpose,
contact [email protected] ************************************************* b.file
_name, b.tablespace_name, decode(c.inc,null,'no','yes') autoextend from sys.dba_
data_files b, sys.filext$ c
select
where c.file# (+)= b.file_id
order by 2, 1;
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact [email protected] *********************************************
****
select tablespace_name, count(*) free_chunks, decode(round((max(bytes) / 1024000
),2),null,0, round((max(bytes) / 1024000),2)) largest_chunk,
nvl(round(sqrt(max(bloc
ks)/sum(blocks))* (100/sqrt(sqrt(count(blocks)) )),2),0) fragmentation_index fro
m sys.dba_free_space group by tablespace_name order by 2 desc, 1;
---------dffrag.sql ************************************************* Copyright 2005 by R
ampant TechPress This script is free for non-commercial purposes with no warrant
ies. Use at your own risk. To license this script for a commercial purpose, cont
act [email protected] ************************************************* b.file_nam
e, b.tablespace_name, nvl(round(sqrt(max(a.blocks)/ sum(a.blocks))*(100/sqrt(sqr
t(count(a.blocks)) )),2),0) fragmentation_index, decode(c.inc,null,'no','yes') a
utoextend, count (*) free_chunks, decode ( round ((max (a.bytes) / 1024000), 2),
null, 0, round ((max (a.bytes) / 1024000), 2)) largest_chunk from sys.dba_free_
space a, sys.dba_data_files b, sys.filext$ c
select
where b.tablespace_name = a.tablespace_name (+) and c.file# (+)= a.file_id and b.
file_id = a.file_id (+) group by b.file_name, decode(c.inc,null,'no','yes'), b.ta
blespace_name order
by 5 desc, 1;
---------tsmap8.sql ************************************************* Copyright 2005 by R
ampant TechPress This script is free for non-commercial purposes with no warrant
ies. Use at your own risk. To license this script for a commercial purpose, cont
act [email protected] ************************************************* 'free spac
e' object_owner, ' ' object_type, ' ' object_name, file_id, block_id, bytes / 10
24 size_kb, blocks
select
from sys.dba_free_space where tablespace_name = <:tablespace name> union all sel
ect owner, segment_type, decode (partition_name,null,segment_name,segment_name |
| '.' || partition_name), file_id,
block_id, bytes / 1024, blocks from sys.dba_exten
ts where tablespace_name = <:tablespace name> order by 4,5;
---------maxext8.sql ************************************************* Copyright 2005 by
Rampant TechPress This script is free for non-commercial purposes with no warran
ties. Use at your own risk. To license this script for a commercial purpose, con
tact [email protected] *************************************************
---------awr_list_seg_block_space.sql ************************************************* C
opyright 2005 by Rampant TechPress This script is free for non-commercial purpos
es with no warranties. Use at your own risk. To license this script for a commer
cial purpose, contact [email protected] ******************************************
*******
drop type BlckFreeSpaceSet; drop type BlckFreeSpace; create type BlckFreeSpace a
s object ( seg_owner varchar2(30), seg_type varchar2(30), seg_name varchar2(100), fs
1 number, fs2 number, fs3 number, fs4 number, fb number ); create type BlckFreeSpaceS
et as table of BlckFreeSpace; create or replace function BlckFreeSpaceFunc (seg_
owner IN varchar2, seg_type in varchar2 default null) return BlckFreeSpaceSet pi
pelined is outRec BlckFreeSpace := BlckFreeSpace(null,null,null,null,null,null,n
ull,null ); fs1_b number; fs2_b number; fs3_b number; fs4_b number; fs1_bl numbe
r; fs2_bl number; fs3_bl number; fs4_bl number; fulb number; fulbl number; u_b n
umber; u_bl number; begin for rec in (select s.owner,s.segment_name,s.segment_ty
pe from dba_segments s w here owner = seg_owner and segment_type = nvl(seg_type,
segment_type) ) loop dbms_space.space_usage ( segment_owner => rec.owner, segmen
t_name => rec.segment_name, segment_type => rec.segment_type, fs1_bytes => fs1_b
,
fs1_blocks
fs2_bytes fs2_blocks fs3_bytes fs3_blocks fs4_bytes fs4_blocks full_byt
es full_blocks unformatted_blocks unformatted_bytes );
=> => => => => => => => => => =>
fs1_bl, fs2_b, fs2_bl, fs3_b, fs3_bl, fs4_b, fs4_bl, fulb, fulbl, u_bl, u_b
outRec.seg_owner := rec.owner; outRec.seg_type := rec.segment_type; outRec.seg_n
ame := rec.segment_name; outRec.fs1 outRec.fs2 outRec.fs3 outRec.fs4 outRec.fb :
= := := := := fs1_bl; fs2_bl; fs3_bl; fs4_bl; fulbl;
Pipe Row (outRec); end loop; return; end; /
---------awr_report_seg_block_space.sql *************************************************
Copyright 2005 by Rampant TechPress This script is free for non-commercial purp
oses with no warranties. Use at your own risk. To license this script for a comm
ercial purpose, contact [email protected] ****************************************
*********
col seg_owner heading 'Segment|Owner' format a10 col seg_type heading 'Segment|T
ype' format a10 col seg_name heading 'Segment|Name' format a30 col col col col c
ol fs1 fs2 fs3 fs4 fb heading heading heading heading heading '0-25%|Free Space'
'25-50%|Free Space' '50-75%|Free Space' '75-100%|Free Space' 'Full|Blocks' form
at format format format format 9,999 9,999 9,999 9,999 9,999
accept user_name prompt break on seg_owner select
Enter Segment Owner:
and instance_number
= &pInstNum
---------sys_stat_int_10g.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk. To license this script for a commercial pur
pose, contact [email protected] *************************************************
e.stat_name "Statistic Name" e.value - b.value "Total" round((e.value - b.value)
/ select avg( extract( day from (e1.end_interval_time-b1.end_interval_time) )*24
*6 extract( hour from (e1.end_interval_time-b1.end_interval_time) )*60*6
select , , ( 0*60+ 0+