Académique Documents
Professionnel Documents
Culture Documents
Danchenkov a
nd Donald K. Burleson --ISBN 0-9744486-2-1
--(c) 2006 by Rampant TechPress - All r
ights reserved. --No portions of this code may be distributed without the expres
s consent of Ram pant TechPress --These scripts are free for non-commercial use
without any warranties. --Use at your own risk!
-- *****************************************************************************
***************************
--oracle10g_quick.ksh -- ************************************************* -- 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 info@rampant.cc -- ***************************
********************** spool rpt_last.lst set pages 9999; set feedback on; set v
erify off; column reads format 999,999,999 column writes format 999,999,999 sele
ct to_char(sn.end_interval_time,'yyyy-mm-dd HH24'), (newreads.value-oldreads.val
ue) reads, (newwrites.value-oldwrites.value) writes from dba_hist_sysstat oldrea
ds, dba_hist_sysstat newreads, dba_hist_sysstat oldwrites, dba_hist_sysstat neww
rites, dba_hist_snapshot sn where newreads.snap_id = (select max(sn.snap_id) fro
m dba_hist_snapshot) and newwrites.snap_id = (select max(sn.snap_id) from dba_hi
st_snapshot) and oldreads.snap_id = sn.snap_id-1 and oldwrites.snap_id = sn.snap
_id-1
and and and and ; prompt prompt prompt prompt prompt prompt prompt prompt prompt
prompt prompt prompt prompt prompt prompt prompt prompt prompt
oldreads.stat_name = 'physical reads' newreads.stat_name = 'physical reads' oldw
rites.stat_name = 'physical writes' newwrites.stat_name = 'physical writes' ****
******************************************************* This will identify any s
ingle file who's read I/O is more than 10% of the total read I/O of the database
. The "hot" file should be examined, and the hot table/index should be identifie
d using STATSPACK. - The busy file should be placed on a disk device with "less
busy" files to minimize read delay and channel contention. - If small file has a
hot small table, place the table in the KEEP pool - If the file has a large-tab
le full-table scan, place the table in the RECYCLE pool and turn on parallel que
ry for the table. ***********************************************************
column mydate format a16 column file_name format a40 column reads format 999,999
,999 select to_char(sn.end_interval_time,'yyyy-mm-dd HH24') mydate, new.filename
file_name, new.phyrds-old.phyrds reads from dba_hist_filestatxs old, dba_hist_f
ilestatxs new, dba_hist_snapshot snw here sn.snap_id = (select max(snap_id) from
dba_hist_snapshot) and new.snap_ id = sn.snap_id and old.snap_id = sn.snap_id-1
and new.filename = old.filename --and -- new.phyrds-old.phyrds > 10000 and (new
.phyrds-old.phyrds)*10 > ( select (newreads.value-oldreads.value) reads from dba
_hist_sysstat oldreads, dba_hist_sysstat newreads, dba_hist_snapshot sn1 where s
n.snap_id = sn1.snap_id and newreads.snap_id = sn.snap_id and oldreads.snap_id =
sn.snap_id-1 and oldreads.stat_name = 'physical reads' and newreads.stat_name =
'physical reads' and (newreads.value-oldreads.value) > 0) ;
prompt prompt prompt prompt prompt prompt prompt prompt prompt prompt prompt pro
mpt prompt prompt prompt
*********************************************************** This will identify a
ny single file who's write I/O is more than 10% of the total write I/O of the da
tabase. The "hot" file should be examined, and the hot table/index should be ide
ntified using STATSPACK. - The busy file should be placed on a disk device with
"less busy" files to minimize write delay and channel channel contention. - If s
mall file has a hot small table, place the table in the KEEP pool **************
*********************************************
column mydate format a16 column file_name format a40 column writes format 999,99
9,999 select to_char(sn.end_interval_time,'yyyy-mm-dd HH24') mydate, new.filenam
e file_name, new.phywrts-old.phywrts writes from dba_hist_filestatxs old, dba_hi
st_filestatxs new, dba_hist_snapshot sn where sn.snap_id = (select max(snap_id)
from dba_hist_snapshot) and new.snap_id = sn.snap_id and old.snap_id = sn.snap_i
d-1 and new.filename = old.filename --and ---- new.phywrts-old.phywrts > 10000 a
nd (new.phywrts-old.phywrts)*10 > (select(newwrites.value-oldwrites.value) write
s from dba_hist_sysstat oldwrites, dba_hist_sysstat newwrites, dba_hist_snapshot
sn1 where sn.snap_id = sn1.snap_id and newwrites.snap_id = sn.snap_id and oldwr
ites.snap_id = sn.snap_id-1 and oldwrites.stat_name = 'physical writes' and neww
rites.stat_name = 'physical writes' and (newwrites.value-oldwrites.value) > 0) ;
prompt *********************************************************** prompt The d
ata buffer hit ratio is controlled by the db_block_buffer or db_cac he_size para
meters. prompt *********************************************************** colum
n column column column logical_reads format 999,999,999 phys_reads format 999,99
9,999 phys_writes format 999,999,999 "BUFFER HIT RATIO" format 999
prompt prompt - If small file has a hot small table, place the table prompt in t
he KEEP pool prompt prompt - If the file has a large-table full-table scan, plac
e prompt the table in the RECYCLE pool and turn on parallel query prompt for the
table. prompt *********************************************************** colum
n mydate format a16 column file_name format a40 column reads format 999,999,999
select to_char(snap_time,'yyyy-mm-dd HH24') mydate, new.filename file_name, new.
phyrds-old.phyrds reads from perfstat.stats$filestatxs old, perfstat.stats$files
tatxs new, perfstat.stats$snapshot sn where sn.snap_id = (select max(snap_id) fr
om stats$snapshot) and new.snap_id = sn.snap_id and old.snap_id = sn.snap_id-1 a
nd new.filename = old.filename --and -- new.phyrds-old.phyrds > 10000 and (new.p
hyrds-old.phyrds)*10 > ( select (newreads.value-oldreads.value) reads from perfs
tat.stats$sysstat oldreads, perfstat.stats$sysstat newreads, perfstat.stats$snap
shot sn1 where sn.snap_id = sn1.snap_id and newreads.snap_id = sn.snap_id and ol
dreads.snap_id = sn.snap_id-1 and oldreads.statistic# = 40 and newreads.statisti
c# = 40 and (newreads.value-oldreads.value) > 0 ) ; prompt prompt prompt prompt
prompt prompt prompt prompt prompt prompt prompt prompt prompt *****************
****************************************** This will identify any single file wh
o's write I/O is more than 10% of the total write I/O of the database. The "hot"
file should be examined, and the hot table/index should be identified using STA
TSPACK. - The busy file should be placed on a disk device with "less busy" files
to minimize write delay and channel channel contention. - If small file has a h
ot small table, place the table in the KEEP pool
prompt few freelists. Find the offending table and add more freelists. prompt **
********************************************************* column buffer_busy_wai
t format 999,999,999 select to_char(snap_time,'dd Mon HH24:mi:ss') mydate, avg(n
ew.buffer_busy_wait-old.buffer_busy_wait) buffer_busy_wait from perfstat.stats$b
uffer_pool_statistics old, perfstat.stats$buffer_pool_statistics new, perfstat.s
tats$snapshot sn where sn.snap_id = (select max(snap_id) from stats$snapshot) an
d new.snap_id = sn.snap_id and new.snap_id = sn.snap_id and old.snap_id = sn.sna
p_id-1 --having -- avg(new.buffer_busy_wait-old.buffer_busy_wait) > 100 group by
to_char(snap_time,'dd Mon HH24:mi:ss') ; prompt prompt prompt prompt **********
************************************************* High redo log space requests i
ndicate a need to increase the log_buffer parameter ****************************
*******************************
column redo_log_space_requests format 999,999,999 select to_char(snap_time,'dd M
on HH24:mi:ss') mydate, newmem.value-oldmem.value redo_log_space_requests from p
erfstat.stats$sysstat oldmem, perfstat.stats$sysstat newmem, perfstat.stats$snap
shot sn where sn.snap_id = (select max(snap_id) from stats$snapshot) --and -- ne
wmem.value-oldmem.value > 30 and newmem.snap_id = sn.snap_id and oldmem.snap_id
= sn.snap_id-1 and oldmem.name = 'redo log space requests' and newmem.name = 're
do log space requests' and newmem.value-oldmem.value > 0 ; prompt prompt prompt
prompt prompt prompt prompt prompt *********************************************
************** Table fetch continued row indicates chained rows, or fetches of l
ong datatypes (long raw, blob) Investigate increasing db_block_size or reorganiz
ing tables with chained rows. **************************************************
*********
column table_fetch_continued_row format 999,999,999 select
prompt prompt prompt prompt prompt prompt prompt prompt prompt prompt prompt pro
mpt prompt prompt prompt
The "hot" file should be examined, and the hot table/index should be identified
using STATSPACK. - The busy file should be placed on a disk device with "less bu
sy" files to minimize read delay and channel contention. - If small file has a h
ot small table, place the table in the KEEP pool - If the file has a large-table
full-table scan, place the table in the RECYCLE pool and turn on parallel query
for the table. ***********************************************************
column mydate format a16 column file_name format a40 column reads format 999,999
,999 select to_char(sn.end_interval_time,'yyyy-mm-dd HH24') mydate, new.filename
file_name, new.phyrds-old.phyrds reads from dba_hist_filestatxs old, dba_hist_f
ilestatxs new, dba_hist_snapshot sn where sn.snap_id = (select max(snap_id) from
dba_hist_snapshot) and new.snap_id = sn.snap_id and old.snap_id = sn.snap_id-1
and new.filename = old.filename --and -- new.phyrds-old.phyrds > 10000 and (new.
phyrds-old.phyrds)*10 > (select(newreads.value-oldreads.value) reads from dba_hi
st_sysstat oldreads, dba_hist_sysstat newreads, dba_hist_snapshot sn1 where sn.s
nap_id = sn1.snap_id and newreads.snap_id = sn.snap_id and oldreads.snap_id = sn
.snap_id-1 and oldreads.stat_name = 'physical reads' and newreads.stat_name = 'p
hysical reads' and (newreads.value-oldreads.value) > 0) ; prompt prompt prompt p
rompt prompt prompt prompt prompt prompt prompt ********************************
*************************** This will identify any single file who's write I/O i
s more than 10% of the total write I/O of the database. The "hot" file should be
examined, and the hot table/index should be identified using STATSPACK. - The b
usy file should be placed on a disk device with "less busy" files to minimize wr
ite delay and channel channel contention.
prompt prompt - If small file has a hot small table, place the table prompt in t
he KEEP pool prompt prompt *****************************************************
****** column mydate format a16 column file_name format a40 column writes format
999,999,999 select to_char(sn.end_interval_time,'yyyy-mm-dd HH24') mydate, new.
filename file_name, new.phywrts-old.phywrts writes from dba_hist_filestatxs old,
dba_hist_filestatxs new, dba_hist_snapshot sn where sn.snap_id = (select max(sn
ap_id) from dba_hist_snapshot) and new.snap_id = sn.snap_id and old.snap_id = sn
.snap_id-1 and new.filename = old.filename --and ---- new.phywrts-old.phywrts >
10000 and (new.phywrts-old.phywrts)*10 > (select (newwrites.value-oldwrites.valu
e) writes from dba_hist_sysstat oldwrites, dba_hist_sysstat newwrites, dba_hist_
snapshot sn1 where sn.snap_id = sn1.snap_id and newwrites.snap_id = sn.snap_id a
nd oldwrites.snap_id = sn.snap_id-1 and oldwrites.stat_name = 'physical writes'
and newwrites.stat_name = 'physical writes' and (newwrites.value-oldwrites.value
) > 0) ; prompt prompt prompt prompt column column column column ***************
******************************************** When the data buffer hit ratio fall
s below 90%, you should consider adding to the db_block_buffer init.ora paramete
r *********************************************************** logical_reads form
at 999,999,999 phys_reads format 999,999,999 phys_writes format 999,999,999 "BUF
FER HIT RATIO" format 999
select to_char(sn.end_interval_time,'dd Mon HH24:mi:ss') mydate, d.value "phys_w
rites", round(100 * (((a.value-e.value)+(b.value-f.value))-(c.value-g.value)) /
((a.value-e.value)+(b.value-f.value))) "BUFFER HIT RATIO" from dba_hist_sysstat
a, dba_hist_sysstat b, dba_hist_sysstat c,
v$shared_pool_advice;
-- change_sga.ksh -- ************************************************* -- Copyri
ght 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 c
ommercial purpose, -- contact info@rampant.cc -- *******************************
****************** #!/bin/ksh # First, we must set the environment . . . . ORACL
E_SID=$1 export ORACLE_SID ORACLE_HOME=`cat /etc/oratab grep ^$ORACLE_SID: cut f2 -d':'` #ORACLE_HOME=`cat /var/opt/oracle/oratab grep ^$ORACLE_SID: cut -f2 -d
':'` export ORACLE_HOME PATH=$ORACLE_HOME/bin:$PATH export PATH $ORACLE_HOME/bin
/sqlplus s /nologin<<! connect system/manager as sysdba; alter system set db_cac
he_size=1500m; alter system set shared_pool_size=500m; alter system set pga_aggr
egate_target=4000m; exit !
-- dss_config.ksh -- ************************************************* -- Copyri
ght 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 c
ommercial purpose, -- contact info@rampant.cc -- *******************************
****************** #!/bin/ksh # First, we must set the environment . . . . ORACL
E_SID=$1 export ORACLE_SID ORACLE_HOME=`cat /etc/oratab grep ^$ORACLE_SID: cut f2 -d':'` #ORACLE_HOME=`cat /var/opt/oracle/oratab grep ^$ORACLE_SID: cut -f2 -d
':'` export ORACLE_HOME PATH=$ORACLE_HOME/bin:$PATH export PATH $ORACLE_HOME/bin
/sqlplus s /nologin<<! connect system/manager as sysdba; alter system set db_cac
he_size=1500m; alter system set shared_pool_size=500m; alter system set pga_aggr
egate_target=4000m;
exit !
-- oltp_config.ksh -- ************************************************* -- Copyr
ight 2005 by Rampant TechPress -- This script is free for non-commercial purpose
s -- with no warranties. Use at your own risk. --- To license this script for a
commercial purpose, -- contact info@rampant.cc -- ******************************
******************* #!/bin/ksh # First, we must set the environment . . . . ORAC
LE_SID=$1 export ORACLE_SID ORACLE_HOME=`cat /etc/oratab grep ^$ORACLE_SID: cut
-f2 -d':'` #ORACLE_HOME=`cat /var/opt/oracle/oratab grep ^$ORACLE_SID: cut -f2 d':'` export ORACLE_HOME PATH=$ORACLE_HOME/bin:$PATH export PATH $ORACLE_HOME/bi
n/sqlplus s /nologin<<! connect system/manager as sysdba; alter system set db_ca
che_size=4000m; alter system set shared_pool_size=500m; alter system set pga_agg
regate_target=1500m; exit !
-- AWR_usage.sql -- ************************************************* -- Copyrig
ht 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 co
mmercial purpose, -- contact info@rampant.cc -- ********************************
***************** select samp.dbid, fu.name, samp.version, detected_usages, tota
l_samples, decode(to_char(last_usage_date, 'MM/DD/YYYY, HH:MI:SS'), NULL, 'FALSE
', to_char(last_sample_date, 'MM/DD/YYYY, HH:MI:SS'), 'TRUE', 'FALSE') currently
_used, first_usage_date, last_usage_date, aux_count, feature_info, last_sample_d
ate, last_sample_period, sample_interval, mt.description from wri$_dbu_usage_sam
ple samp, wri$_dbu_feature_usage fu, wri$_dbu_feature_metadata mt where samp.dbi
d = fu.dbid and samp.version = fu.version and
fu.name = mt.name and fu.name not like '_DBFUS_TEST%' and /* filter out test fea
tures */ bitand(mt.usg_det_method, 4) != 4 /* filter out disabled features */
---------phys_disk_reads_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 info@rampant.cc ***********************************************
**
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 ;
---------rpt_10g_sysstat.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with n
o warranties. Use at your own risk. To license this script for a commercial purp
ose, contact info@rampant.cc *************************************************
prompt prompt This will query the dba_hist_sysstat to display all values prompt
that exceed the value specified in prompt the "where" clause of the query. promp
t set pages 999 break on snap_time skip 2 accept stat_name char prompt 'Enter St
atistic Name: '; accept stat_value number prompt 'Enter Statistics Threshold val
ue: '; col snap_time col value select format a19 format 999,999,999
set pages 999 accept stat_name char prompt 'Enter Statistic Name: '; col snap_ti
me col avg_value format a19 format 999,999,999
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 ) ;
---------wait_time_detail_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 info@rampant.cc **********************************************
***
prompt prompt This will compare values from dba_hist_waitstat with prompt detail
information from dba_hist_active_sess_history. prompt set pages 999 set lines 8
0 break on snap_time skip 2 col col col col snap_time file_name object_type obje
ct_name heading heading heading heading 'Snap Time' 'File Name' 'Object Type' 'O
bject Name' format format format format a20 a40 a10 a20
and and and and and and and and and and order
b.dbid(+) = &pDbId e.dbid = &pDbId b.dbid(+) = e.dbid b.instance_number(+) = &pI
nstNum e.instance_number = &pInstNum b.instance_number(+) = e.instance_number b.
eq_type(+) = e.eq_type b.req_reason(+) = e.req_reason e.total_wait# - nvl(b.tota
l_wait#,0) > 0 l.type(+) = e.eq_type by wttm desc, waits desc)
---------metric_summary.sql ************************************************* Copyright 2
005 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 purpo
se, contact info@rampant.cc *************************************************
select metric_name Metric Name , metric_unit "Metric Unit", minval "Minimum Valu
e", maxval "Maximum Value", average "Average Value" from DBA_HIST_SYSMETRIC_SUMM
ARY where snap_id = &pEndSnap and dbid = &pDbId and instance_number = &pInstNum
---------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 info@rampant.cc ********************************************
*****
column "Statistic Name" format A40 column "Time (s)" format 999,999 column "Perc
ent of Total DB Time" format 999,999 select e.stat_name "Statistic Name" , (e.va
lue - b.value)/1000000 , decode( e.stat_name,'DB time' , to_number(null) , 100*(
e.value - b.value) "Time (s)"
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact info@rampant.cc *********************************************
**** TOTAL_WAITS format 999,999,999 PCT_WAITS format 99.99 TIME_WAITED format 99
9,999,999 PCT_TIME format 99.99 WAIT_CLASS format A20
column column column column column
SELECT wait_class, total_waits, ROUND(100 * (total_waits / sum_waits),2) pct_wai
ts, time_waited, ROUND(100 * (time_waited / sum_time),2) pct_time FROM (SELECT w
ait_class, total_waits, time_waited FROM v$system_wait_class WHERE wait_class !=
'Idle'), (SELECT SUM(total_waits) sum_waits, SUM(time_waited) sum_time FROM v$s
ystem_wait_class WHERE wait_class != 'Idle') ORDER BY 5 DESC;
-- hot_files_ash.sql -- ************************************************* -- Cop
yright 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 commercial purpose, -- contact info@rampant.cc -- ****************************
********************* SELECT f.file_name Data File , COUNT(*) Wait Number , SUM(
h.time_waited) Total Time Waited FROM v$active_session_history h, dba_data_files
f WHERE h.current_file# = f.file_id GROUP BY f.file_name ORDER BY 3 DESC
----events_waits_hr_ash.sql ************************************************* Copyri
ght 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 co
mmercial purpose, -- contact info@rampant.cc -- ********************************
***************** SELECT h.event "Wait Event", SUM(h.wait_time + h.time_waited)
"Total Wait Time" FROM v$active_session_history h, v$event_name e WHERE h.sample
_time BETWEEN sysdate - 1/24 AND sysdate AND h.event_id = e.event_id AND e.wait_
class <> 'Idle' GROUP BY h.event ORDER BY 2 DESC
-- user_waits_hr_ash.sql -- ************************************************* -Copyright 2005 by Rampant TechPress -- This script is free for non-commercial p
urposes -- with no warranties. Use at your own risk. --- To license this script
for a commercial purpose, -- contact info@rampant.cc -- ************************
************************* SELECT s.sid, s.username, SUM(h.wait_time + h.time_wai
ted) "total wait time" FROM v$active_session_history h, v$session s, v$event_nam
e e WHERE h.sample_time BETWEEN sysdate - 1/24 AND sysdate AND h.session_id = s.
sid AND e.event_id = h.event_id AND e.wait_class <> 'Idle' AND s.username IS NOT
NULL GROUP BY s.sid, s.username ORDER BY 3
---------sql_waits_hr_ash.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 info@rampant.cc *************************************************
-- To license this script for a commercial purpose, -- contact info@rampant.cc - ************************************************* SELECT b.username, a.stat_na
me, round((a.value / 1000000),3) time_secs FROM v$sess_time_model a, v$session b
WHERE a.sid = b.sid AND b.sid = 123 ORDER BY 3 DESC
-- bhr_hr_ash.sql -- ************************************************* -- Copyri
ght 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 c
ommercial purpose, -- contact info@rampant.cc -- *******************************
****************** SELECT Buffer Cache Hit Ratio Metric Name , to_char(begin_tim
e, hh24:mi:ss ) Begin , to_char(end_time, hh24:mi:ss ) End , round(value,2) Valu
e FROM v$sysmetric_history WHERE Metric_name = Buffer Cache Hit Ratio ORDER BY B
egin_time DESC;
-- class_waits_hr_ash.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 info@rampant.cc -- ***********************
************************** SELECT c.wait_class "Wait Class", to_char(h.begin_tim
e,'hh24:mi:ss') "Begin", to_char(h.end_time,'hh24:mi:ss') "End", h.average_waite
r_count, h.time_waited, h.wait_count FROM v$waitclassmetric_history h, v$system_
wait_class c WHERE c.wait_class_id = h.wait_class_id
-- cpu_hot_sessions.sql -- ************************************************* -Copyright 2005 by Rampant TechPress -- This script is free for non-commercial pu
rposes -- with no warranties. Use at your own risk. --- To license this script f
or a commercial purpose, -- contact info@rampant.cc -- *************************
************************ select s.sid, s.username FROM v$sessmetric sm, v$sessio
n s WHERE s.sid = sm.session_id AND (sm.cpu/(SELECT decode(value,0,-1) FROM v$sy
smetric WHERE metric_name = 'cpu usage per sec') *100) > 1;
-- wait_class.sql -- ************************************************* -- Copyri
ght 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 c
ommercial purpose, -- contact info@rampant.cc -- *******************************
****************** SELECT c.wait_class "Wait Class", to_char(h.begin_time,'hh24:
mi:ss') "Begin", to_char(h.end_time,'hh24:mi:ss') "End", h.average_waiter_count,
h.time_waited, h.wait_count FROM v$waitclassmetric_history h, v$system_wait_cla
ss c WHERE c.wait_class_id = h.wait_class_id AND c.wait_class = 'Application' plug-in your metric name here ORDER BY h.begin_time DESC;
-- metric_by_time.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 info@rampant.cc -- ***************************
********************** SELECT to_char(m.begin_time,'hh24:mi') "start time", to_c
har(m.end_time,'hh24:mi') "end time", n.name, m.time_waited, m.num_sess_waiting,
m.wait_count FROM v$eventmetric m, v$event_name n WHERE m.event_id = n.event_id
AND n.wait_class <> 'Idle' -- add your event metric name here AND m.time_waited
> 0 ORDER BY 4 DESC;
-- avg_io_time.sql -- ************************************************* -- Copyr
ight 2005 by Rampant TechPress -- This script is free for non-commercial purpose
s -- with no warranties. Use at your own risk. --- To license this script for a
commercial purpose, -- contact info@rampant.cc -- ******************************
******************* SELECT to_char(m.begin_time,'hh24:mi') "start time", to_char
(m.end_time,'hh24:mi') "end time", f.file_name, s.lstiotim "last i/o time", m.av
erage_read_time + m.average_write_time "average i/o time" FROM v$filemetric m, d
ba_data_files f, v$filestat s WHERE m.file_id = f.file_id AND s.file# = f.file_i
d AND s.lstiotim > (m.average_read_time + m.average_write_time);
-----metric_by_time.sql ************************************************* Copyright 2
005 by Rampant TechPress This script is free for non-commercial purposes with no
warranties. Use at your own risk.
---------sys_time_model_pct_db_time.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 info@rampant.cc ****************************************
*********
SELECT e.stat_name "E.STAT_NAME" , Round((e.value - b.value)/1000000,2)"Time (s)
" , Round(decode( e.stat_name,'DB time' , to_number(null) , 100*(e.value - b.val
ue) )/ (SELECT NVL((e1.value - b1.value),-1) FROM dba_hist_sys_time_model e1 , d
ba_hist_sys_time_model b1 WHERE b1.snap_id = b.snap_id AND e1.snap_id = e.snap_i
d AND b1.dbid = b.dbid AND e1.dbid = e.dbid AND b1.instance_number = b.instance_
number AND e1.instance_number = e.instance_number AND e1.stat_name = 'DB time' A
ND b1.stat_id = e1.stat_id ),2) "Percent of Total DB Time" FROM dba_hist_sys_tim
e_model e , dba_hist_sys_time_model b WHERE b.snap_id = &pBgnSnap AND e.snap_id
= &pEndSnap AND b.dbid = &pDbId AND e.dbid = &pDbId AND b.instance_number = &pIn
stNum AND e.instance_number = &pInstNum AND b.stat_id = e.stat_id AND e.value b.value > 0 ORDER BY 2 DESC from v$system_event where event like %wait% ;
---------display_cache_advice.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 info@rampant.cc **********************************************
***
;
---------wait_time_detail_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 info@rampant.cc **********************************************
***
prompt prompt This will compare values from dba_hist_waitstat with prompt detail
information from dba_hist_active_sess_history. prompt set pages 999 set lines 8
0 break on snap_time skip 2 col col col col col col snap_time file_name object_t
ype object_name wait_count time heading heading heading heading heading heading
'Snap Time' 'File Name' 'Object Type' 'Object Name' 'Wait Count' 'Time' format f
ormat format format format format a20 a40 a10 a20 999,999 999,999
select to_char(begin_interval_time,'yyyy-mm-dd hh24:mi') snap_time, -- file_name
, object_type, object_name, wait_count, time from dba_hist_waitstat wait, dba_hi
st_snapshot snap, dba_hist_active_sess_history ash, dba_data_files df, dba_objec
ts obj where wait.snap_id = snap.snap_id and wait.snap_id = ash.snap_id and df.f
ile_id = ash.current_file# and obj.object_id = ash.current_obj# and wait_count >
50 order by to_char(begin_interval_time,'yyyy-mm-dd hh24:mi'), file_name ;
col c3 heading
Rows Processed
format 99,999,999
select * from ( select to_char(s.begin_interval_time,'mm-dd hh24') c0, p.object_
name c1, sum(t.disk_reads_total) c2, sum(t.rows_processed_total) c3, DENSE_RANK(
) OVER (PARTITION BY to_char(s.begin_interval_time,'mm-dd hh24') ORDER BY SUM(t.
disk_reads_total) desc) AS rnk 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 p.objec
t_type like '%TABLE%' group by to_char(s.begin_interval_time,'mm-dd hh24'), p.ob
ject_name order by c0 desc, rnk ) where rnk <= 5 ;
---------awr_sql_object_freq.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 info@rampant.cc ***********************************************
** c1 c2 c3 c4 heading heading heading heading Object Name Operation Option Obje
ct Count format format format format a30 a15 a15 999,999
col col col col
break on c1 skip 2 break on c2 skip 2 select p.object_name c1, p.operation c2, p
.options c3, count(1) c4 from dba_hist_sql_plan p,
and x.state !=0 and o.owner# !=0 group by set_ds,o.name) bh where ds.set_id >= p
d.bp_lo_sid and ds.set_id <= pd.bp_hi_sid and pd.bp_size != 0 and ds.addr=bh.set
_ds;
---------fileio7.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 info@rampant.cc *************************************************
select d.name file_name, c.name tablespace_name, b.phyrds, b.phywrts, b.phyblkrd
, b.phyblkwrt, b.readtim, b.writetim from sys.v_$datafile a, sys.v_$filestat b,
sys.ts$ c, sys.v_$dbfile d, sys.file$ e where a.file# = b.file# and a.file# = d.
file# and e.ts# = c.ts# and e.file# = d.file# order by b.phyrds desc;
----fileio8plus.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 info@rampant.cc *********************************************
****
select d.name file_name, c.name tablespace_name, b.phyrds, b.phywrts, b.phyblkrd
, b.phyblkwrt, b.readtim, b.writetim from sys.v_$datafile a, sys.v_$filestat b,
sys.ts$ c, sys.v_$dbfile d, sys.file$ e where a.file# = b.file# and a.file# = d.
file# and e.ts# = c.ts# and e.file# = d.file# union all select v.fnnam file_name
, c.name tablespace_name, b.phyrds, b.phywrts, b.phyblkrd, b.phyblkwrt, b.readti
m, b.writetim from sys.v_$tempfile a, sys.v_$tempstat b, sys.ts$ c, sys.x$kccfn
v, sys.x$ktfthc hc where a.file# = b.file# and a.file# = hc.ktfthctfno and hc.kt
fthctsn = c.ts# and v.fntyp = 7 and v.fnnam is not null and v.fnfno = hc.ktfthct
fno and hc.ktfthctsn = c.ts#
order by 3 desc;
---------globiostats.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 info@rampant.cc *************************************************
select name, value from sys.v_$sysstat where name in ('consistent changes', 'con
sistent gets', 'db block changes', 'db block gets', 'physical reads', 'physical
writes', 'sorts (disk)', 'user commits', 'user rollbacks' ) order by 1;
---------buffratio.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 info@rampant.cc *************************************************
select 100 100 * (round ((sum (decode (name, 'physical reads', value, 0)) sum (d
ecode (name, 'physical reads direct', value, 0)) sum (decode (name, 'physical re
ads 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', 'physical read
s direct (lob)', 'physical reads', 'physical reads direct');
---------fileio.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 info@rampant.cc *************************************************
rem rem NAME: fileio.sql rem rem FUNCTION: Reports on the file io status of all
of the rem FUNCTION: datafiles in the database. 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 for
mat 999.99 heading 'Block Read Ratio' column bwratio format 999.99 heading 'Bloc
k Write Ratio' column phyrds heading 'Physical Reads' column phywrts heading 'Ph
ysical Writes' column phyblkrd heading 'Physical Block Reads' column phyblkwrt h
eading 'Physical Block Writes' column name format a45 heading 'File Name' column
file# format 9999 heading 'File' column dt new_value today noprint select to_ch
ar(sysdate,'ddmonyyyyhh24miss') dt from dual; 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 sys.v_$filestat a; select nvl(sum(b.phyrds+b.phywrts),0) sum_io2 from sys.
v_$tempstat b; select &st1+&st2 sum_io from dual; rem @title132 'File I/O Statis
tics Report' spool rep_out\&db\fileio&&today
temp_io_per_sec number; begin open get_io; for i in 1..2 loop fetch get_io into
sum_io1, sum_io2; if i = 1 then sum_io12:=sum_io1; else sum_io22:=sum_io2; end i
f; end loop; select sum_io12+sum_io22 into tot_io from dual; select sysdate into
now from dual; select ceil((now-max(startup_time))*(60*60*24)) into elapsed_sec
onds from gv$ins tance; fixed_io_per_sec:=sum_io12/elapsed_seconds; temp_io_per_
sec:=sum_io22/elapsed_seconds; tot_io_per_sec:=tot_io/elapsed_seconds; dbms_outp
ut.put_line('Elapsed Sec :' to_char(elapsed_seconds, '9,999,999.99')); dbms_outp
ut.put_line('Fixed IO/SEC:' to_char(fixed_io_per_sec,'9,999,999.99')); dbms_outp
ut.put_line('Temp IO/SEC :' to_char(temp_io_per_sec, '9,999,999.99')); dbms_outp
ut.put_line('Total IO/SEC:' to_char(tot_io_Per_Sec, '9,999,999.99')); end; /
---------col col col col col col col col col
wait_report.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 info@rampant.cc ************************************************* event
format a30 heading 'Event Name' waits format 999,999,999 heading 'Total Waits'
average_wait format 999,999,999 heading 'Average Waits' time_waited format 999,9
99,999 heading 'Time Waited' total_time new_value divide_by noprint value new_va
lue val noprint percent format 999.990 heading 'Percent Of Non-Idle Waits' durat
ion new_value millisec noprint p_of_total heading 'Percent of Total Uptime' form
at 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 fr
om v$system_event where total_waits-total_timeouts>0 and event not like 'SQL*Net
%' and event not like 'smon%' and event not like 'pmon%' and event not like 'rdb
ms%'
and event not like 'PX%' and event not like 'sbt%' and event not in ('gcs remote
message','ges remote message','virtual cir cuit status','dispatcher timer') ; s
elect value from v$sysstat where name ='CPU used when call started'; @title132 '
System Events Percent' break on report compute sum of time_waited on report spoo
l rep_out/&db/sys_events select name event, 0 waits, 0 average_wait, value time_
waited, value/(&÷_by+&&val)*100 Percent, value/&&millisec*100 p_of_total f
rom v$sysstat where name ='CPU used when call started' union select event, total
_waits-total_timeouts waits, time_waited/(total_waits-total_timeouts) average_wa
it, time_waited, time_waited/(&÷_by+&&val)*100 Percent, time_waited/&&mill
isec*100 P_of_total from v$system_event where total_waits-total_timeouts>0 and e
vent not like 'SQL*Net%' and event not like 'smon%' and event not like 'pmon%' a
nd event not like 'rdbms%' and event not like 'PX%' and event not like 'sbt%' an
d event not in ('gcs remote message','ges remote message','virtual cir cuit stat
us','dispatcher timer') and time_waited>0 order by percent desc / spool off clea
r columns ttitle off clear computes clear breaks
---------toptables.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 info@rampant.cc *************************************************
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.comma
nd_type , 2, 'insert ' , 3,'select ', 6, 'update ' , 7, 'delete ' , 26,'table lo
ck ') command , 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.a
ddress 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 ) ) wh
ere rownum <= 100;
---------largescan9i.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 info@rampant.cc *************************************************
'slave wait', 'virtual circuit status', 'WMON goes to sleep', 'jobq slave wait',
'Queue Monitor Wait', 'wakeup time manager', 'PX Idle Wait') AND event not like
'DFS%' AND event not like 'KXFX%') order by 4 desc, 1 asc;
---------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 info@rampant.cc *************************************************
select sid, username, round(100 * total_user_io/total_io,2) tot_io_pct from (sel
ect b.sid sid, nvl(b.username,p.name) username, sum(value) total_user_io from sy
s.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
('physical reads', 'physical writes', 'physical writes direct', 'physical reads
direct', 'physical writes direct (lob)', 'physical reads direct (lob)') group by
b.sid, nvl(b.username,p.name)), (select sum(value) total_io from sys.v_$statnam
e c, sys.v_$sesstat a where a.statistic#=c.statistic# and c.name in ('physical r
eads', 'physical writes', 'physical writes direct',
'physical reads direct', 'physical writes direct (lob)', 'physical reads direct
(lob)')) order by 3 desc;
---------totpctio.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 info@rampant.cc ************************************************* SID, USE
RNAME, ROUND(100 * TOTAL_USER_IO/TOTAL_IO,2) TOT_IO_PCT
SELECT
FROM (SELECT b.SID SID, nvl(b.USERNAME,p.NAME) USERNAME, SUM(VALUE) TOTAL_USER_I
O 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 ('physical reads','physical writes', 'consistent changes','consistent g
ets', 'db block gets','db block changes', 'physical writes direct', 'physical re
ads direct', 'physical writes direct (lob)', 'physical reads direct (lob)') GROU
P BY b.SID, nvl(b.USERNAME,p.name)), (select sum(value) TOTAL_IO from sys.V_$STA
TNAME c, sys.V_$SESSTAT a WHERE a.STATISTIC#=c.STATISTIC# and c.NAME in ('physic
al reads','physical writes', 'consistent changes', 'consistent gets','db block g
ets', 'db block changes', 'physical writes direct', 'physical reads direct', 'ph
ysical writes direct (lob)',
------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 ************************************************* event, total_waits, round(1
00 * (total_waits / sum_waits),2) pct_tot_waits, time_wait_sec, round(100 * (tim
e_wait_sec / sum_secs),2) pct_secs_waits, total_timeouts, avg_wait_sec
select
from (select event, total_waits, round((time_waited / 100),2) time_wait_sec, tot
al_timeouts, round((average_wait / 100),2) avg_wait_sec from sys.v_$system_event
where event not in ('lock element cleanup ', 'pmon timer ', 'rdbms ipc message
', 'smon timer ', 'SQL*Net message from client ', 'SQL*Net break/reset to client
', 'SQL*Net message to client ', 'SQL*Net more data to client ', 'dispatcher ti
mer ', 'Null event ', 'parallel query dequeue wait ', 'parallel query idle wait
- Slaves ', 'pipe get ', 'PL/SQL lock timer ', 'slave wait ', 'virtual circuit s
tatus ', 'WMON goes to sleep') and event not like 'DFS%' and event not like 'KXF
X%'), (select sum(total_waits) sum_waits, sum(round((time_waited / 100),2)) sum_
secs from sys.v_$system_event where event not in ('lock element cleanup ', 'pmon
timer ', 'rdbms ipc message ', 'smon timer ', 'SQL*Net message from client ', '
SQL*Net break/reset to client ', 'SQL*Net message to client ', 'SQL*Net more dat
a to client ',
'dispatcher timer ', 'Null event ', 'parallel query dequeue wait ', 'parallel qu
ery idle wait - Slaves ', 'pipe get ', 'PL/SQL lock timer ', 'slave wait ', 'vir
tual circuit status ', 'WMON goes to sleep') and event not like 'DFS%' and event
not like 'KXFX%') order by 2 desc;
---------col col col col col
sum_read_waits.sql ************************************************* Copyright 2
005 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 purpo
se, contact info@rampant.cc ************************************************* c1
c2 c3 c4 c5 heading heading heading heading heading 'Average Waits forFull Scan
Read I/O' 'Average Waits for Index Read I/O' 'Percent of I/O Waits for Full Sca
ns' 'Percent of I/O Waits for Index Scans' 'Starting Value for optimizer index c
ost adj' format format format format format 9999.999 9999.999 9.99 9.99 999
select a.average_wait b.average_wait a.total_waits /(a.total_waits + b.total_wai
ts) b.total_waits /(a.total_waits + b.total_waits) (b.average_wait / a.average_w
ait)*100 from v$system_event a, v$system_event b where a.event = 'db file scatte
red read' and b.event = 'db file sequential read' ; ? phys_reads.sql break on be
gin_interval_time skip 2 column phyrds format 999,999,999 column begin_interval_
time format a25 select begin_interval_time, filename,
c1, c2, c3, c4, c5
phywrts desc ;
---------snapfileio_10g.sql ************************************************* Copyright 2
005 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 purpo
se, contact info@rampant.cc *************************************************
rem rem NAME: snapfileio.sql rem FUNCTION: Reports on the file io status of all
of the rem FUNCTION: datafiles in the database for a single snapshot. column col
umn column column column column column column column column column column sum_io
1 new_value st1 noprint sum_io2 new_value st2 noprint sum_io new_value divide_by
noprint Percent format 999.999 heading 'Percent Of IO' brratio format 999.99 he
ading 'Block Read Ratio' bwratio format 999.99 heading 'Block Write Ratio' phyrd
s heading 'Physical Reads' phywrts heading 'Physical Writes' phyblkrd heading 'P
hysical Block Reads' phyblkwrt heading 'Physical Block Writes' filename format a
45 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;
select nvl(sum(b.phyrds+b.phywrts),0) sum_io2 from dba_hist_tempstatxs b where s
nap_id=&&snap; select &st1+&st2 sum_io from dual; rem @title132 'Snap&&snap File
I/O Statistics Report' spool rep_out\&db\fileio&&snap select a.filename, a.phyr
ds, a.phywrts, (100*(a.phyrds+a.phywrts)/÷_by) Percent, a.phyblkrd, a.phyb
lkwrt, (a.phyblkrd/greatest(a.phyrds,1)) brratio, (a.phyblkwrt/greatest(a.phywrt
s,1)) bwratio from
old.snap_id = sn.snap_id-1 ;
---------rpt_bhr_oracle8.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with n
o warranties. Use at your own risk. To license this script for a commercial purp
ose, contact info@rampant.cc *************************************************
set pages 9999; column column column column logical_reads format 999,999,999 phy
s_reads format 999,999,999 phys_writes format 999,999,999 "BUFFER HIT RATIO" for
mat 999
select to_char(snap_time,'yyyy-mm-dd HH24'), a.value + b.value "logical_reads",
c.value "phys_reads", d.value "phys_writes", round(100 * (((a.value-e.value)+(b.
value-f.value))-(c.value-g.value)) / (a.value-e.value)+(b.value-f.v value))) "BU
FFER HIT RATIO" from perfstat.stats$sysstat a, perfstat.stats$sysstat b, perfsta
t.stats$sysstat c, perfstat.stats$sysstat d, perfstat.stats$sysstat e, perfstat.
stats$sysstat f, perfstat.stats$sysstat g, perfstat.stats$snapshot sn where a.sn
ap_id = sn.snap_id and b.snap_id = sn.snap_id and c.snap_id = sn.snap_id and d.s
nap_id = sn.snap_id and e.snap_id = sn.snap_id-1 and f.snap_id = sn.snap_id-1 an
d g.snap_id = sn.snap_id-1 and a.statistic# = 39 and e.statistic# = 39
------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 *************************************************
set pages 999; column bhr format 9.99 column mydate heading 'yr. mo dy Hr.' sele
ct to_char(end_interval_time,'day') mydate, avg( (((new.consistent_gets-old.cons
istent_gets)+ (new.db_block_gets-old.db_block_gets))(new.physical_reads-old.phys
ical_reads)) / ((new.consistent_gets-old.consistent_gets)+ (new.db_block_gets-ol
d.db_block_gets)) ) bhr from dba_hist_buffer_pool_stat old, dba_hist_buffer_pool
_stat new, dba_hist_snapshot sn where new.name in ('DEFAULT','FAKE VIEW') and ne
w.name = old.name and new.snap_id = sn.snap_id and old.snap_id = sn.snap_id-1 an
d new.consistent_gets > 0 and old.consistent_gets > 0 having avg( (((new.consist
ent_gets-old.consistent_gets)+ (new.db_block_gets-old.db_block_gets))(new.physic
al_reads-old.physical_reads)) / ((new.consistent_gets-old.consistent_gets)+ (new
.db_block_gets-old.db_block_gets)) ) < 1 group by to_char(end_interval_time,'day
') ;
-----rpt_lib_cache_hr.sql ************************************************* Copyright
2005 by Rampant TechPress This script is free for non-commercial purposes with
no warranties. Use at your own risk.
select '4k ' status as status, count(*) as num from v$bh where file# in( select
file_id from dba_data_files where tablespace_name in ( select tablespace_name fr
om dba_tablespaces where block_size=4096)) group by '4k ' status union select '2
k ' status as status, count(*) as num from v$bh where file# in( select file_id f
rom dba_data_files where tablespace_name in ( select tablespace_name from dba_ta
blespaces where block_size=2048)) group by '2k ' status union select status, cou
nt(*) as num from v$bh where status='free' group by status order by 1 / spool of
f ttitle off
-----------obj_xtab.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 info@rampant.cc ************************************************* Crosstab
of object and statistic for an owner by Mike Ault www.oracle-script.com
col "Object" format a20 set numwidth 12 set lines 132
; select 'alter ' s.segment_type ' ' t1.owner '.' s.segment_name ' storage (buff
er_pool keep);' from t1, dba_segments s where s.segment_name = t1.object_name a
nd s.owner = t1.owner and s.segment_type = t1.object_type and nvl(s.partition_na
me,'-') = nvl(t1.subobject_name,'-') and buffer_pool <> 'KEEP' and object_type i
n ('TABLE','INDEX') group by s.segment_type, t1.owner, s.segment_name having (su
m(num_blocks)/greatest(sum(blocks), .001))*100 > 80 ;
---------9i_recycle_syntax.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 info@rampant.cc *************************************************
set pages 999; set heading off; set feedback off; ttitle off; spool keep_syntax.
sql -- *********************************************************** -- First, get
the table list -- *********************************************************** s
elect 'alter table ' p.owner '.' p.name ' storage (buffer_pool recycle);' from d
ba_tables t, dba_segments s, v$sqlarea a, (select distinct address,
and t.owner = p.owner having sum(s.executions) > 9 group by p.owner, p.name, t.n
um_rows order by sum(s.executions) desc; --*************************************
************ -- Index Report Section --*****************************************
******** column column column column column column nbr_scans num_rows tbl_blocks
owner table_name index_name format format format format format format 999,999,9
99 999,999,999 999,999,999 a9; a20; a20;
ttitle 'Index full scans and counts' select p.owner, d.table_name, p.name index_
name, seg.blocks tbl_blocks, sum(s.executions) nbr_scans from dba_segments seg,
v$sqlarea s, dba_indexes d, (select distinct address, object_owner owner, object
_name name from v$sql_plan where operation = 'INDEX' and options = 'FULL SCAN')
p where d.index_name = p.name and s.address = p.address and d.table_name = seg.s
egment_name and seg.owner = p.owner having sum(s.executions) > 9 group by p.owne
r, d.table_name, p.name, seg.blocks order by sum(s.executions) desc; ttitle 'Ind
ex range scans and counts' select p.owner,
-----with no warranties. Use at your own risk. To license this script for a commercia
l purpose, contact info@rampant.cc *********************************************
**** format a13 format a15 format a25 format 9,999,999 format 9,999,999
col c1 heading Owner col c2 heading Object Type col c3 heading Object Name col c
4 heading Average CPU Cost col c5 heading Average IO Cost break on c1 skip 2 bre
ak on c2 skip 2 select p.object_owner c1, p.object_type c2, p.object_name c3, av
g(p.cpu_cost) c4, avg(p.io_cost) c5 from dba_hist_sql_plan p where p.object_name
is not null and p.object_owner <> 'SYS' group by p.object_owner, p.object_type,
p.object_name order by 1,2,4 desc ;
---------awr_sql_object_char_detail.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 info@rampant.cc ****************************************
*********
accept tabname prompt Enter Table Name: col col col col col col c0 c1 c2 c3 c4 c
5 heading heading heading heading heading heading Begin Interval time Owner Obje
ct Type Object Name Average CPU Cost Average IO Cost format format format format
format format a8 a10 a10 a15 9,999,999 9,999,999
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, dba_hi
st_snapshot sn where p.object_name is not null and p.object_owner <> 'SYS' and p
.object_name = 'CUSTOMER_DETS' and p.sql_id = st.sql_id and st.snap_id = sn.snap
_id group by to_char(sn.begin_interval_time,'mm-dd hh24'), p.object_owner, p.obj
ect_type, p.object_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 info@rampant.cc *********************************************
**** 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 select Nested
Join Threshold &nested_thr
col c4 heading
Object Count
format 999,999
break on c1 skip 2 break on c2 skip 2 select to_char(sn.begin_interval_time,'yymm-dd hh24') c1, p.operation c2, p.options c3, count(1) c4 from dba_hist_sql_pla
n p, dba_hist_sqlstat s, dba_hist_snapshot sn where p.object_owner <> 'SYS' and
p.sql_id = s.sql_id and s.snap_id = sn.snap_id group by to_char(sn.begin_interva
l_time,'yy-mm-dd hh24'), p.operation, p.options 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 info@rampant.cc ************************************************
*
col c1 heading Begin Interval Time format a20 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 from ( select to_char(sn.begin_interval_time,'yy-mm-dd hh24') c1,
count(1) c2 from dba_hist_sql_plan p, dba_hist_sqlstat s, dba_hist_snapshot sn w
here p.object_owner <> 'SYS' and
p.operation like '%TABLE ACCESS%' and p.options 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, ( 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, dba_hist_snaps
hot sn where p.object_owner <> 'SYS' and 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 hh24') 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 info@rampant.cc **********************************************
***
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 format a20 fo
rmat 999,999
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,'da
y') order by 1;
---------awr_sql_scan_sums.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 info@rampant.cc *************************************************
c1 c2 c3 c4 heading heading heading heading Begin Large Small Total Interval Ti
me Table Full Table Scans Table Full Table Scans Index Scans format format forma
t format a20 999,999 999,999 999,999
col col col col
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%'
---------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 info@rampant.cc *****************************************
********
col c1 heading Begin Interval Time format a20 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 from ( select to_char(sn.begin_interval_time,'day') c1, count(1) c
2 from dba_hist_sql_plan p, dba_hist_sqlstat s, dba_hist_snapshot sn where p.obj
ect_owner <> 'SYS' and p.operation like '%TABLE ACCESS%' and p.options like '%IN
DEX%' and p.sql_id = s.sql_id and s.snap_id = sn.snap_id group by to_char(sn.beg
in_interval_time,'day') order by 1 ) i, ( select to_char(sn.begin_interval_time,
'day') c1, count(1) c2 from dba_hist_sql_plan p, dba_hist_sqlstat s, dba_hist_sn
apshot sn where p.object_owner <> 'SYS' and 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,'day') order by 1 ) f where i.c1 = f.c1 ;
---------awr_hash_join_alert.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 info@rampant.cc ***********************************************
** c1 c2 c3 c4 c5 heading heading heading heading heading Date Hash Join Count R
ows 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 hash_thr char prompt ttitle
Enter Hash Join Threshold:
Hash Join Threshold &hash_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) c5
from dba_hist_snapshot sn, dba_hist_sql_plan p, dba_hist_sqlstat st where st.sql
_id = p.sql_id and sn.snap_id = st.snap_id and p.operation = 'HASH JOIN' having
count(*) > &hash_thr group by begin_interval_time;
sample_time > sysdate - 1/24/60 and session_type <> group by sql_id order by cou
nt(*) desc; BACKGROUND
---------ash_display_sql_io_waits.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 info@rampant.cc ******************************************
*******
select ash.sql_id, count(*) from v$active_session_history ash, v$event_name evt
where ash.sample_time > sysdate 1/24/60 and ash.session_state = WAITING and ash.
event_id = evt.event_id and evt.wait_class = User I/O group by sql_id order by c
ount(*) desc;
---------ash_event_rollup.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 info@rampant.cc *************************************************
ttitle 'High waits on events Rollup by hour'
------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 *************************************************
select TO_CHAR(h.sample_time,'Day') "Hour", sum(h.wait_time/100) "Total Wait Tim
e (Sec)" from v$active_session_history h, v$event_name n where h.session_state =
'ON CPU' and h.session_type = 'FOREGROUND' and h.event_id = n.EVENT_ID and n.wa
it_class <> 'Idle' group by TO_CHAR(h.sample_time,'Day');
---------ash_total_event_wait_time.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 info@rampant.cc *****************************************
********
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;
return; end; /
---------free_space_by_segment.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 info@rampant.cc *********************************************
****
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
Enter Segment Owner:
select * from Table ( BlckFreeSpaceFunc ('&user_name', 'TABLE' ) ) order by fs4
desc ;
---------block_count.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 info@rampant.cc *************************************************
DECLARE v_unformatted_blocks number; v_unformatted_bytes number; v_fs1_blocks nu
mber; v_fs1_bytes number; v_fs2_blocks number; v_fs2_bytes number; v_fs3_blocks
number;