You are on page 1of 86

/export/home/oracle/metzray

#### plan_hash_value.sql #######


set echo off
set lines 180
col begin_interval_time format a30
SELECT ws.snap_id,
wsn.BEGIN_INTERVAL_TIME,
ws.SQL_ID,
ws.PLAN_HASH_VALUE,
ws.EXECUTIONS_TOTAL,
ws.ROWS_PROCESSED_TOTAL,
ws.ELAPSED_TIME_TOTAL
from
sys.WRH$_SQLSTAT ws,
sys.WRM$_SNAPSHOT wsn
where ws.snap_id
=
wsn.snap_id
AND
ws.sql_id='&SQL_ID' order by 2
/
set echo off

[LNACSU3]oracle@acsu2 $ cat plan_hash_value_all.sql


set lines 200
col BEGIN_INTERVAL_TIME format a30
SELECT ws.snap_id,
wsn.BEGIN_INTERVAL_TIME,
ws.SQL_ID,
ws.PLAN_HASH_VALUE,
ws.EXECUTIONS_TOTAL,
ws.ROWS_PROCESSED_TOTAL,
ws.ELAPSED_TIME_TOTAL
FROM
sys.WRH$_SQLSTAT ws,
sys.WRM$_SNAPSHOT wsn
WHERE ws.snap_id
=
wsn.snap_id
AND
ws.sql_id
IN
(
SELECT sql_id
FROM
(
SELECT DISTINCT
ws.sql_id,
ws.PLAN_HASH_VALUE
FROM
sys.WRH$_SQLSTAT ws,
sys.WRM$_SNAPSHOT wsn
WHERE ws.snap_id
=
wsn.snap_id
)
GROUP BY sql_id
HAVING COUNT(*)>1
)
ORDER BY ws.sql_id,
wsn.BEGIN_INTERVAL_TIME
/

[LNCRPD1]oracle@crmd2 $ cat shrink_anal.sql


set linesize 200

set pagesize 200


col
col
col
col

"Tablespace"
"Segment Name"
"Datafile Location"
"Highwater Mark (Mb)"

format a20
format a45 heading "Segment|Name"
format a50 heading "Datafile|Location"
heading "Highwater|Mark (Mb)"

select ddf.tablespace_name "Tablespace", ddf.file_name "Datafile Location", ddf.


bytes/(1024*1024) "Size (Mb)",
round(((hwm.maximum+de.blocks-1)*dbs.db_block_size)/(1024*1024),2) "Highw
ater Mark (Mb)",
de.owner||'.'||de.segment_name "Segment Name", de.segment_type "Type"
from dba_data_files ddf, (select file_id, max(block_id) maximum
from dba_extents
group by file_id) hwm,
dba_extents de, (select value db_block_size
from v$parameter
where name='db_block_size') dbs
where ddf.file_id = hwm.file_id
and de.file_id = hwm.file_id
and de.block_id = hwm.maximum
order by 1, 2, 6, 5 ;

[LNCRPD1]oracle@crmd2 $ cat who_dropped.sql


set echo off
/*===================================================================
||
|| Filename:
who_dropped.sql
||
|| Purpose:
DB specific, who dropped an object
||
|| Views:
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
||
===================================================================*/
col userid forma a10
col name forma a16
col tperf forma a20 head 'Time Performed'
col obj$name forma a23
col returncode forma 999999 head 'Return'
col spare1 forma a8 head 'o/s user'
select ac.userid,ac.spare1,aa.name,ac.obj$name,to_char(ac.timestamp,'YYYY-MON-DD
HH24:MI:SS') tperf, ac.returncode
from aud_copy ac, audit_actions aa
where ac.action = aa.action
and ac.action = 12
and ac.obj$name in ('............','...............')
order by ac.timestamp

[LNCRPD1]oracle@crmd2 $ cat redo_info.sql


set lines 500
select '******************************************************' from dual;
select '****
Redo Log Files and Sizing
****' from dual;
select '******************************************************' from dual;
timing start 'Redo Sizing';
set heading on;
col "File Name" for a80;
col "Size in MB" format 999,999,999,999,990
select substr(a.member,1,80) as "File Name",b.bytes/1024/1024 as "Size in MB" fr
om v$logfile a,v$log b where a.group#=b.group#;
timing stop 'Redo Sizing';
set heading off;
select '******************************************************' from dual;
select '****
Redolog Switch Rate by Date and Hour
****' from dual;
select '******************************************************' from dual;
timing start Redo;
set heading on;
col Total for a5;
col h00 for a3;
col h01 for a3;
col h02 for a3;
col h03 for a3;
col h04 for a3;
col h05 for a3;
col h06 for a3;
col h07 for a3;
col h08 for a3;
col h09 for a3;
col h10 for a3;
col h11 for a3;
col h12 for a3;
col h13 for a3;
col h14 for a3;
col h15 for a3;
col h16 for a3;
col h17 for a3;
col h18 for a3;
col h19 for a3;
col h20 for a3;
col h21 for a3;
col h22 for a3;
col h23 for a3;
col h24 for a3;
break on report
compute max of "Total" on report
compute max of "h00" on report
compute max of "h01" on report
compute max of "h02" on report
compute max of "h03" on report
compute max of "h04" on report
compute max of "h05" on report

compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute
compute

max
max
max
max
max
max
max
max
max
max
max
max
max
max
max
max
max
max

of
of
of
of
of
of
of
of
of
of
of
of
of
of
of
of
of
of

"h06"
"h07"
"h08"
"h09"
"h10"
"h11"
"h12"
"h13"
"h14"
"h15"
"h16"
"h17"
"h18"
"h19"
"h20"
"h21"
"h22"
"h23"

on
on
on
on
on
on
on
on
on
on
on
on
on
on
on
on
on
on

report
report
report
report
report
report
report
report
report
report
report
report
report
report
report
report
report
report

SELECT trunc(first_time) "Date",


to_char(first_time, 'Dy') "Day",
substr(count(1),1,5) as "Total",
substr(SUM(decode(to_char(first_time, 'hh24'),'00',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'01',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'02',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'03',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'04',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'05',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'06',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'07',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'08',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'09',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'10',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'11',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'12',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'13',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'14',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'15',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'16',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'17',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'18',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'19',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'20',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'21',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'22',1,0)),1,3)
substr(SUM(decode(to_char(first_time, 'hh24'),'23',1,0)),1,3)
FROM
V$log_history
group by trunc(first_time), to_char(first_time, 'Dy')
Order by 1;

as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as
as

"h00",
"h01",
"h02",
"h03",
"h04",
"h05",
"h06",
"h07",
"h08",
"h09",
"h10",
"h11",
"h12",
"h13",
"h14",
"h15",
"h16",
"h17",
"h18",
"h19",
"h20",
"h21",
"h22",
"h23"

clear breaks
timing stop Redo;
set heading off;
select '******************************************************' from dual;
select '**** Redolog Daily and Hourly volume calculated ****' from dual;
select '******************************************************' from dual;
timing start Redovol;

--##############################################################################
#########
--##
PL/SQL used here to gather and display average redo volumes
##
--##############################################################################
#########
set serveroutput on;
declare
v_log
v_days
v_logsz
v_adsw
V_advol
v_ahsw
v_ahvol

number;
number;
number;
number;
number;
number;
number;

begin
select count(first_time) into v_log from v$log_history;
select count(distinct(to_char(first_time,'dd-mon-rrrr'))) into v_days from v$log
_history;
select max(bytes)/1024/1024 into v_logsz from v$log;
v_adsw := round(v_log / v_days);
v_advol := round(v_adsw * v_logsz);
v_ahsw := round(v_adsw / 24);
v_ahvol := round((v_adsw / 24 )) * v_logsz;
dbms_output.put ('Total Switches' || ' '||v_log||' ==> ');
dbms_output.put ('Total Days' || ' '|| v_days||' ==> ');
dbms_output.put_line ('Redo Size' || ' ' || v_logsz);
dbms_output.put ('Avg Daily Switches' || ' ' || v_adsw||' ==> ');
dbms_output.put_line ('Avg Daily Volume in Meg' || ' ' || v_advol);
dbms_output.put ('Avg Hourly Switches' || ' ' || v_ahsw||' ==> ');
dbms_output.put_line ('Avg Hourly Volume in Meg' || ' ' || v_ahvol);
end;
/

[LNDGSNP1]oracle@dgsnp1 $ cat active_temp.sql


set pages 100
set linesize 1000
set trimspool on
--define USERNAME=&USER
set verify off
column sql_text head "SQL Statement" format a50 word_wrap
column username format a15

column sid_serial# format a10 head "Session| Id "


column username head "Oracle|User"
column osuser head "Oper|User" format a10
column blocks format 99999 head "BLCKS"
column extents format 99999 head "EXTS"
prompt
prompt
prompt
spool active_temp.log
SELECT s.sid||','|| s.serial# sid_serial#,
DECODE(s.username,null,s.program,s.username) Username,
concat_sqltext(a.address,a.hash_value) sql_text,
s.osuser,
a.executions,
a.disk_reads,
u.segblk#,
u.extents,
u.blocks
FROM v$session s,
v$sqlarea a,
v$sort_usage u
WHERE s.status='ACTIVE'
AND s.type != 'BACKGROUND'
AND s.sql_address = a.address
AND s.sql_hash_value = a.hash_value
AND a.hash_value = u.sqlhash
AND s.audsid <> userenv('sessionid')
AND UPPER(s.username) LIKE UPPER('&USERNAME')||'%'
/
spool off
prompt
prompt
set verify on
set term on
set pages 24
set echo on

[LNDGSNP1]oracle@dgsnp1 $ cat rac_diag.sql


set feedback off
column timecol new_value timestamp
column spool_extension new_value suffix
select to_char(sysdate,'Mondd_hhmi') timecol,
'.out' spool_extension from sys.dual;
column output new_value dbname
select value || '_' output
from v$parameter where name = 'db_name';
spool racdiag_&&dbname&tamp&&suffix
set lines 200
set pagesize 35
set trim on
set trims on
alter session set nls_date_format = 'MON-DD-YYYY HH24:MI:SS';
alter session set timed_statistics = true;
set feedback on
select to_char(sysdate) time from dual;
set numwidth 5
column host_name format a20 tru
select inst_id, instance_name, host_name, version, status, startup_time
from gv$instance
order by inst_id;
set echo on
-- Taking Hang Analyze dumps
-- This may take a little while...
oradebug setmypid
oradebug unlimit
oradebug -g all hanganalyze 3
-- This part may take the longest, you can monitor bdump or udump to see if the
-- file is being generated.
oradebug -g all dump systemstate 266
-- WAITING SESSIONS:
-- The entries that are shown at the top are the sessions that have
-- waited the longest amount of time that are waiting for non-idle wait
-- events (event column). You can research and find out what the wait
-- event indicates (along with its parameters) by checking the Oracle
-- Server Reference Manual or look for any known issues or documentation
-- by searching Metalink for the event name in the search bar. Example
-- (include single quotes): [ 'buffer busy due to global cache' ].
-- Metalink and/or the Server Reference Manual should return some useful
-- information on each type of wait event. The inst_id column shows the
-- instance where the session resides and the SID is the unique identifier
-- for the session (gv$session). The p1, p2, and p3 columns will show
-- event specific information that may be important to debug the problem.
-- To find out what the p1, p2, and p3 indicates see the next section.
-- Items with wait_time of anything other than 0 indicate we do not know
-- how long these sessions have been waiting.
-set numwidth 10
column state format a7 tru
column event format a25 tru
column last_sql format a40 tru
select sw.inst_id, sw.sid, sw.state, sw.event, sw.seconds_in_wait seconds,
sw.p1, sw.p2, sw.p3, sa.sql_text last_sql

from gv$session_wait sw, gv$session s, gv$sqlarea sa


where sw.event not in
('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and sw.seconds_in_wait > 0
and (sw.inst_id = s.inst_id and sw.sid = s.sid)
and (s.inst_id = sa.inst_id and s.sql_address = sa.address)
order by seconds desc;
-- EVENT PARAMETER LOOKUP:
-- This section will give a description of the parameter names of the
-- events seen in the last section. p1test is the parameter value for
-- p1 in the WAITING SESSIONS section while p2text is the parameter
-- value for p3 and p3 text is the parameter value for p3. The
-- parameter values in the first section can be helpful for debugging
-- the wait event.
-column event format a30 tru
column p1text format a25 tru
column p2text format a25 tru
column p3text format a25 tru
select distinct event, p1text, p2text, p3text
from gv$session_wait sw
where sw.event not in ('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and seconds_in_wait > 0
order by event;
-- GES LOCK BLOCKERS:
-- This section will show us any sessions that are holding locks that
-- are blocking other users. The inst_id will show us the instance that
-- the session resides on while the sid will be a unique identifier for
-- the session. The grant_level will show us how the GES lock is granted to
-- the user. The request_level will show us what status we are trying to obtain.
-- The lockstate column will show us what status the lock is in. The last column
-- shows how long this session has been waiting.
-set numwidth 5
column state format a16 tru;
column event format a30 tru;
select dl.inst_id, s.sid, p.spid, dl.resource_name1,
decode(substr(dl.grant_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as grant_level,
decode(substr(dl.request_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as request_level,
decode(substr(dl.state,1,8),'KJUSERGR','Granted','KJUSEROP','Opening',
'KJUSERCA','Canceling','KJUSERCV','Converting') as state,
s.sid, sw.event, sw.seconds_in_wait sec
from gv$ges_enqueue dl, gv$process p, gv$session s, gv$session_wait sw
where blocker = 1

and (dl.inst_id = p.inst_id and dl.pid = p.spid)


and (p.inst_id = s.inst_id and p.addr = s.paddr)
and (s.inst_id = sw.inst_id and s.sid = sw.sid)
order by sw.seconds_in_wait desc;
-- GES LOCK WAITERS:
-- This section will show us any sessions that are waiting for locks that
-- are blocked by other users. The inst_id will show us the instance that
-- the session resides on while the sid will be a unique identifier for
-- the session. The grant_level will show us how the GES lock is granted to
-- the user. The request_level will show us what status we are trying to obtain.
-- The lockstate column will show us what status the lock is in. The last column
-- shows how long this session has been waiting.
-set numwidth 5
column state format a16 tru;
column event format a30 tru;
select dl.inst_id, s.sid, p.spid, dl.resource_name1,
decode(substr(dl.grant_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as grant_level,
decode(substr(dl.request_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as request_level,
decode(substr(dl.state,1,8),'KJUSERGR','Granted','KJUSEROP','Opening',
'KJUSERCA','Cancelling','KJUSERCV','Converting') as state,
s.sid, sw.event, sw.seconds_in_wait sec
from gv$ges_enqueue dl, gv$process p, gv$session s, gv$session_wait sw
where blocked = 1
and (dl.inst_id = p.inst_id and dl.pid = p.spid)
and (p.inst_id = s.inst_id and p.addr = s.paddr)
and (s.inst_id = sw.inst_id and s.sid = sw.sid)
order by sw.seconds_in_wait desc;
-- LOCAL ENQUEUES:
-- This section will show us if there are any local enqueues. The inst_id will
-- show us the instance that the session resides on while the sid will be a
-- unique identifier for. The addr column will show the lock address. The type
-- will show the lock type. The id1 and id2 columns will show specific parameter
s
-- for the lock type.
-set numwidth 12
column event format a12 tru
select l.inst_id, l.sid, l.addr, l.type, l.id1, l.id2,
decode(l.block,0,'blocked',1,'blocking',2,'global') block,
sw.event, sw.seconds_in_wait sec
from gv$lock l, gv$session_wait sw
where (l.sid = sw.sid and l.inst_id = sw.inst_id)
and l.block in (0,1)
order by l.type, l.inst_id, l.sid;
---------

LATCH HOLDERS:
If there is latch contention or 'latch free' wait events in the WAITING
SESSIONS section we will need to find out which proceseses are holding
latches. The inst_id will show us the instance that the session resides
on while the sid will be a unique identifier for. The username column
will show the session's username. The os_user column will show the os
user that the user logged in as. The name column will show us the type
of latch being waited on. You can search Metalink for the latch name in

-- the search bar. Example (include single quotes):


-- [ 'library cache' latch ]. Metalink should return some useful information
-- on the type of latch.
-set numwidth 5
select distinct lh.inst_id, s.sid, s.username, p.username os_user, lh.name
from gv$latchholder lh, gv$session s, gv$process p
where (lh.sid = s.sid and lh.inst_id = s.inst_id)
and (s.inst_id = p.inst_id and s.paddr = p.addr)
order by lh.inst_id, s.sid;
-- LATCH STATS:
-- This view will show us latches with less than optimal hit ratios
-- The inst_id will show us the instance for the particular latch. The
-- latch_name column will show us the type of latch. You can search Metalink
-- for the latch name in the search bar. Example (include single quotes):
-- [ 'library cache' latch ]. Metalink should return some useful information
-- on the type of latch. The hit_ratio shows the percentage of time we
-- successfully acquired the latch.
-column latch_name format a30 tru
select inst_id, name latch_name,
round((gets-misses)/decode(gets,0,1,gets),3) hit_ratio,
round(sleeps/decode(misses,0,1,misses),3) "SLEEPS/MISS"
from gv$latch
where round((gets-misses)/decode(gets,0,1,gets),3) < .99
and gets != 0
order by round((gets-misses)/decode(gets,0,1,gets),3);
-- No Wait Latches:
-select inst_id, name latch_name,
round((immediate_gets/(immediate_gets+immediate_misses)), 3) hit_ratio,
round(sleeps/decode(immediate_misses,0,1,immediate_misses),3) "SLEEPS/MISS"
from gv$latch
where round((immediate_gets/(immediate_gets+immediate_misses)), 3) < .99
and immediate_gets + immediate_misses > 0
order by round((immediate_gets/(immediate_gets+immediate_misses)), 3);
-- GLOBAL CACHE CR PERFORMANCE
-- This shows the average latency of a consistent block request.
-- AVG CR BLOCK RECEIVE TIME should typically be about 15 milliseconds depending
-- on your system configuration and volume, is the average latency of a
-- consistent-read request round-trip from the requesting instance to the holdin
g
-- instance and back to the requesting instance. If your CPU has limited idle ti
me
-- and your system typically processes long-running queries, then the latency ma
y
-- be higher. However, it is possible to have an average latency of less than on
e
-- millisecond with User-mode IPC. Latency can be influenced by a high value for
-- the DB_MULTI_BLOCK_READ_COUNT parameter. This is because a requesting process
-- can issue more than one request for a block depending on the setting of this
-- parameter. Correspondingly, the requesting process may wait longer. Also chec
k
-- interconnect badwidth, OS tcp settings, and OS udp settings if
-- AVG CR BLOCK RECEIVE TIME is high.
-set numwidth 20

column "AVG CR BLOCK RECEIVE TIME (ms)" format 9999999.9


select b1.inst_id, b2.value "GCS CR BLOCKS RECEIVED",
b1.value "GCS CR BLOCK RECEIVE TIME",
((b1.value / b2.value) a.sql active.sql active_rbs.sql active_temp.sql activep.s
ql activew.sql applied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm
_create_dg_ext_red.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_powe
r.sql asm_drop_disk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_
logs_applied.sql check_logs_recd.sql check_primary_stus.sql column_settings.sql
concat_sqltext.sql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql crea
te_cdrs_user.sql create_indexes_restore.sql create_indexes_restore2.sql create_s
cripts.ksh create_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql
desc.sql dict_temp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sq
l epoc.sql explain2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.
sql freeblocks.sql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 g
et_extents.sql get_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glo
gin.sql how_to_start_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage
.sql lockers.sql locks.sql locks2.sql long_runners.sql long_running_jobs.sql lon
gops.sql minshpool.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monito
r_temp_space.sql next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_
size.sql open_cursor_count.sql output.sql priv_users.sql proc_syntax.sql proc_tr
iggers.sql rac_diag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful
_scripts2.log useful_scripts3.log 10) "AVG CR BLOCK RECEIVE TIME (ms)"
from gv$sysstat b1, gv$sysstat b2
where b1.name = 'global cache cr block receive time' and
b2.name = 'global cache cr blocks received' and b1.inst_id = b2.inst_id ;
-- GLOBAL CACHE LOCK PERFORMANCE
-- This shows the average global enqueue get time.
-- Typically AVG GLOBAL LOCK GET TIME should be 20-30 milliseconds. the elapsed
-- time for a get includes the allocation and initialization of a new global
-- enqueue. If the average global enqueue get (global cache get time) or average
-- global enqueue conversion times are excessive, then your system may be
-- experiencing timeouts. See the 'WAITING SESSIONS', 'GES LOCK BLOCKERS',
-- 'GES LOCK WAITERS', and 'TOP 10 WAIT EVENTS ON SYSTEM' sections if the
-- AVG GLOBAL LOCK GET TIME is high.
-set numwidth 20
column "AVG GLOBAL LOCK GET TIME (ms)" format 9999999.9
select b1.inst_id, (b1.value + b2.value) "GLOBAL LOCK GETS",
b3.value "GLOBAL LOCK GET TIME",
(b3.value / (b1.value + b2.value) a.sql active.sql active_rbs.sql active_temp.sq
l activep.sql activew.sql applied_logs.sql archivelog_histogram.sql asm_add_disk
_dg.sql asm_create_dg_ext_red.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg
_rebal_power.sql asm_drop_disk_dg.sql asm_used_space.sql blockers.sql buffer_map
.sql check_logs_applied.sql check_logs_recd.sql check_primary_stus.sql column_se
ttings.sql concat_sqltext.sql connect.sql connect_setup.sql cpu_usage.sql cr_inv
al.sql create_cdrs_user.sql create_indexes_restore.sql create_indexes_restore2.s
ql create_scripts.ksh create_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_b
ackups.sql desc.sql dict_temp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user
_cashown.sql epoc.sql explain2.sql explain3.sql file_ts.sql free_used_blocks.sql
freeblock.sql freeblocks.sql freeblocksts.sql freespce.sql freespce734.sql free
spce_pre8 get_extents.sql get_part.sql get_set_newnames.sql get_sql.sql get_sqlt
ext.sql glogin.sql how_to_start_auto_recovery.sql indcol.sql lib_locks.sql local
_temp_usage.sql lockers.sql locks.sql locks2.sql long_runners.sql long_running_j
obs.sql longops.sql minshpool.sql mon_locks.sql mon_rec_proc.sql mon_rec_process
.sql monitor_temp_space.sql next_extent_fail.sql next_extent_fail_max.sql next_e
xtent_fail_size.sql open_cursor_count.sql output.sql priv_users.sql proc_syntax.
sql proc_triggers.sql rac_diag.sql ray_sql.tar useful_scripts.log useful_scripts
.tar useful_scripts2.log useful_scripts3.log 10) "AVG GLOBAL LOCK GET TIME (ms)"
from gv$sysstat b1, gv$sysstat b2, gv$sysstat b3

where b1.name = 'global lock sync gets' and


b2.name = 'global lock async gets' and b3.name = 'global lock get time'
and b1.inst_id = b2.inst_id and b2.inst_id = b3.inst_id;
-- RESOURCE USAGE
-- This section will show how much of our resources we have used.
-set numwidth 8
select inst_id, resource_name, current_utilization, max_utilization,
initial_allocation
from gv$resource_limit
where max_utilization > 0
order by inst_id, resource_name;
-- DLM TRAFFIC INFORMATION
-- This section shows how many tickets are available in the DLM. If the
-- TCKT_WAIT columns says "YES" then we have run out of DLM tickets which could
-- cause a DLM hang. Make sure that you also have enough TCKT_AVAIL.
-set numwidth 5
select a.sql active.sql active_rbs.sql active_temp.sql activep.sql activew.sql a
pplied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm_create_dg_ext_r
ed.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_power.sql asm_drop_d
isk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_logs_applied.sql
check_logs_recd.sql check_primary_stus.sql column_settings.sql concat_sqltext.s
ql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql create_cdrs_user.sql
create_indexes_restore.sql create_indexes_restore2.sql create_scripts.ksh creat
e_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql desc.sql dict_te
mp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sql epoc.sql expla
in2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.sql freeblocks.s
ql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 get_extents.sql g
et_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glogin.sql how_to_s
tart_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage.sql lockers.sql
locks.sql locks2.sql long_runners.sql long_running_jobs.sql longops.sql minshpo
ol.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monitor_temp_space.sql
next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_size.sql open_cu
rsor_count.sql output.sql priv_users.sql proc_syntax.sql proc_triggers.sql rac_d
iag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful_scripts2.log us
eful_scripts3.log from gv$dlm_traffic_controller
order by TCKT_AVAIL;
-- DLM MISC
-set numwidth 10
select a.sql active.sql active_rbs.sql active_temp.sql activep.sql activew.sql a
pplied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm_create_dg_ext_r
ed.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_power.sql asm_drop_d
isk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_logs_applied.sql
check_logs_recd.sql check_primary_stus.sql column_settings.sql concat_sqltext.s
ql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql create_cdrs_user.sql
create_indexes_restore.sql create_indexes_restore2.sql create_scripts.ksh creat
e_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql desc.sql dict_te
mp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sql epoc.sql expla
in2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.sql freeblocks.s
ql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 get_extents.sql g
et_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glogin.sql how_to_s
tart_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage.sql lockers.sql
locks.sql locks2.sql long_runners.sql long_running_jobs.sql longops.sql minshpo
ol.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monitor_temp_space.sql
next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_size.sql open_cu

rsor_count.sql output.sql priv_users.sql proc_syntax.sql proc_triggers.sql rac_d


iag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful_scripts2.log us
eful_scripts3.log from gv$dlm_misc;
-- LOCK CONVERSION DETAIL:
-- This view shows the types of lock conversion being done on each instance.
-select a.sql active.sql active_rbs.sql active_temp.sql activep.sql activew.sql a
pplied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm_create_dg_ext_r
ed.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_power.sql asm_drop_d
isk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_logs_applied.sql
check_logs_recd.sql check_primary_stus.sql column_settings.sql concat_sqltext.s
ql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql create_cdrs_user.sql
create_indexes_restore.sql create_indexes_restore2.sql create_scripts.ksh creat
e_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql desc.sql dict_te
mp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sql epoc.sql expla
in2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.sql freeblocks.s
ql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 get_extents.sql g
et_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glogin.sql how_to_s
tart_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage.sql lockers.sql
locks.sql locks2.sql long_runners.sql long_running_jobs.sql longops.sql minshpo
ol.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monitor_temp_space.sql
next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_size.sql open_cu
rsor_count.sql output.sql priv_users.sql proc_syntax.sql proc_triggers.sql rac_d
iag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful_scripts2.log us
eful_scripts3.log from gv$lock_activity;
-- TOP 10 WRITE PINGING/FUSION OBJECTS
-- This view shows the top 10 objects for write pings accross instances.
-- The inst_id column shows the node that the block was pinged on. The name
-- column shows the object name of the offending object. The file# shows the
-- offending file number (gc_files_to_locks). The STATUS column will show the
-- current status of the pinged block. The READ_PINGS will show us read converts
-- and the WRITE_PINGS will show us objects with write converts. Any rows that
-- show up are objects that are concurrently accessed across more than 1 instanc
e.
-set numwidth 8
column name format a20 tru
column kind format a10 tru
select inst_id, name, kind, file#, status, BLOCKS,
READ_PINGS, WRITE_PINGS
from (select p.inst_id, p.name, p.kind, p.file#, p.status,
count(p.block#) BLOCKS, sum(p.forced_reads) READ_PINGS,
sum(p.forced_writes) WRITE_PINGS
from gv$ping p, gv$datafile df
where p.file# = df.file# (+)
group by p.inst_id, p.name, p.kind, p.file#, p.status
order by sum(p.forced_writes) desc)
where rownum < 11
order by WRITE_PINGS desc;
---------

TOP 10 READ PINGING/FUSION OBJECTS


This view shows the top 10 objects for read pings. The inst_id column shows
the node that the block was pinged on. The name column shows the object name
of the offending object. The file# shows the offending file number
(gc_files_to_locks). The STATUS column will show the current status of the
pinged block. The READ_PINGS will show us read converts and the WRITE_PINGS
will show us objects with write converts. Any rows that show up are objects
that are concurrently accessed across more than 1 instance.

-set numwidth 8
column name format a20 tru
column kind format a10 tru
select inst_id, name, kind, file#, status, BLOCKS,
READ_PINGS, WRITE_PINGS
from (select p.inst_id, p.name, p.kind, p.file#, p.status,
count(p.block#) BLOCKS, sum(p.forced_reads) READ_PINGS,
sum(p.forced_writes) WRITE_PINGS
from gv$ping p, gv$datafile df
where p.file# = df.file# (+)
group by p.inst_id, p.name, p.kind, p.file#, p.status
order by sum(p.forced_reads) desc)
where rownum < 11
order by READ_PINGS desc;
-- TOP 10 FALSE PINGING OBJECTS
-- This view shows the top 10 objects for false pings. This can be avoided by
-- better gc_files_to_locks configuration. The inst_id column shows the node
-- that the block was pinged on. The name column shows the object name of the
-- offending object. The file# shows the offending file number
-- (gc_files_to_locks). The STATUS column will show the current status of the
-- pinged block. The READ_PINGS will show us read converts and the WRITE_PINGS
-- will show us objects with write converts. Any rows that show up are objects
-- that are concurrently accessed across more than 1 instance.
-set numwidth 8
column name format a20 tru
column kind format a10 tru
select inst_id, name, kind, file#, status, BLOCKS,
READ_PINGS, WRITE_PINGS
from (select p.inst_id, p.name, p.kind, p.file#, p.status,
count(p.block#) BLOCKS, sum(p.forced_reads) READ_PINGS,
sum(p.forced_writes) WRITE_PINGS
from gv$false_ping p, gv$datafile df
where p.file# = df.file# (+)
group by p.inst_id, p.name, p.kind, p.file#, p.status
order by sum(p.forced_writes) desc)
where rownum < 11
order by WRITE_PINGS desc;
-- INITIALIZATION PARAMETERS:
-- Non-default init parameters for each node.
-set numwidth 5
column name format a30 tru
column value format a50 wra
column description format a60 tru
select inst_id, name, value, description
from gv$parameter
where isdefault = 'FALSE'
order by inst_id, name;
-- TOP 10 WAIT EVENTS ON SYSTEM
-- This view will provide a summary of the top wait events in the db.
-set numwidth 10
column event format a25 tru
select inst_id, event, time_waited, total_waits, total_timeouts
from (select inst_id, event, time_waited, total_waits, total_timeouts

from gv$system_event where event not in ('rdbms ipc message','smon timer',


'pmon timer', 'SQL*Net message from client','lock manager wait for remote messag
e',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
order by time_waited desc)
where rownum < 11
order by time_waited desc;
-- SESSION/PROCESS REFERENCE:
-- This section is very important for most of the above sections to find out
-- which user/os_user/process is identified to which session/process.
-set numwidth 7
column event format a30 tru
column program format a25 tru
column username format a15 tru
select p.inst_id, s.sid, s.serial#, p.pid, p.spid, p.program, s.username,
p.username os_user, sw.event, sw.seconds_in_wait sec
from gv$process p, gv$session s, gv$session_wait sw
where (p.inst_id = s.inst_id and p.addr = s.paddr)
and (s.inst_id = sw.inst_id and s.sid = sw.sid)
order by p.inst_id, s.sid;
-- SYSTEM STATISTICS:
-- All System Stats with values of > 0. These can be referenced in the
-- Server Reference Manual
-set numwidth 5
column name format a60 tru
column value format 9999999999999999999999999
select inst_id, name, value
from gv$sysstat
where value > 0
order by inst_id, name;
-- CURRENT SQL FOR WAITING SESSIONS:
-- Current SQL for any session in the WAITING SESSIONS list
-set numwidth 5
column sql format a80 wra
select sw.inst_id, sw.sid, sw.seconds_in_wait sec, sa.sql_text sql
from gv$session_wait sw, gv$session s, gv$sqlarea sa
where sw.sid = s.sid (+)
and sw.inst_id = s.inst_id (+)
and s.sql_address = sa.address
and sw.event not in ('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and seconds_in_wait > 0
order by sw.seconds_in_wait desc;
-- Taking Hang Analyze dumps
-- This may take a little while...
oradebug setmypid

oradebug unlimit
oradebug -g all hanganalyze 3
-- This part may take the longest, you can monitor bdump or udump to see if the
-- file is being generated.
oradebug -g all dump systemstate 266
set echo off
select to_char(sysdate) time from dual;
spool off
-- --------------------------------------------------------------------------Prompt;
Prompt racdiag output files have been written to:;
Prompt;
host pwd
Prompt alert log and trace files are located in:;
column host_name format a12 tru
column name format a20 tru
column value format a60 tru
select distinct i.host_name, p.name, p.value
from gv$instance i, gv$parameter p
where p.inst_id = i.inst_id (+)
and p.name like '%_dump_dest'
and p.name != 'core_dump_dest';
- - - - - - - - - - - - - - - - Script ends here - - - - - - - - - - - - - - - Sample Output:
-------------TIME
-------------------AUG-11-2001 12:06:36
1 row selected.
INST_ID
------1 V9201
2 V9202

INSTANCE_NAME HOST_NAME VERSION STATUS STARTUP_TIME


---------------- -------------------- -------------- ------- ----------opcbsol1 9.2.0.1.0 OPEN AUG-01-2002
opcbsol2 9.2.0.1.0 OPEN JUL-09-2002

2 rows selected.
SQL>
SQL> -- Taking Hanganalyze Dumps
SQL> -- This may take a little while...
SQL> oradebug setmypid
Statement processed.
SQL> oradebug unlimit
Statement processed.
SQL> oradebug setinst all
Statement processed.
SQL> oradebug -g def hanganalyze 3
Hang Analysis in /u02/32bit/app/oracle/admin/V9232/bdump/v92321_diag_29495.trc

SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>

------------------

WAITING SESSIONS:
The entries that are shown at the top are the sessions that have
waited the longest amount of time that are waiting for non-idle wait
events (event column). You can research and find out what the wait
event indicates (along with its parameters) by checking the Oracle
Server Reference Manual or look for any known issues or documentation
by searching Metalink for the event name in the search bar. Example
(include single quotes): [ 'buffer busy due to global cache' ].
Metalink and/or the Server Reference Manual should return some useful
information on each type of wait event. The inst_id column shows the
instance where the session resides and the SID is the unique identifier
for the session (gv$session). The p1, p2, and p3 columns will show
event specific information that may be important to debug the problem.
To find out what the p1, p2, and p3 indicates see the next section.
Items with wait_time of anything other than 0 indicate we do not know
how long these sessions have been waiting.

EM' sections if the


-- AVG GLOBAL LOCK GET TIME is high.
-set numwidth 20
column "AVG GLOBAL LOCK GET TIME (ms)" format 9999999.9
select b1.inst_id, (b1.value + b2.value) "GLOBAL LOCK GETS",
b3.value "GLOBAL LOCK GET TIME",
(b3.value / (b1.value + b2.value) a.sql active.sql active_rbs.sql active_temp.sq
l activep.sql activew.sql applied_logs.sql archivelog_histogram.sql asm_add_disk
_dg.sql asm_create_dg_ext_red.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg
_rebal_power.sql asm_drop_disk_dg.sql asm_used_space.sql blockers.sql buffer_map
.sql check_logs_applied.sql check_logs_recd.sql check_primary_stus.sql column_se
ttings.sql concat_sqltext.sql connect.sql connect_setup.sql cpu_usage.sql cr_inv
al.sql create_cdrs_user.sql create_indexes_restore.sql create_indexes_restore2.s
ql create_scripts.ksh create_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_b
ackups.sql desc.sql dict_temp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user
_cashown.sql epoc.sql explain2.sql explain3.sql file_ts.sql free_used_blocks.sql
freeblock.sql freeblocks.sql freeblocksts.sql freespce.sql freespce734.sql free
spce_pre8 get_extents.sql get_part.sql get_set_newnames.sql get_sql.sql get_sqlt
ext.sql glogin.sql how_to_start_auto_recovery.sql indcol.sql lib_locks.sql local
_temp_usage.sql lockers.sql locks.sql locks2.sql long_runners.sql long_running_j
obs.sql longops.sql minshpool.sql mon_locks.sql mon_rec_proc.sql mon_rec_process
.sql monitor_temp_space.sql next_extent_fail.sql next_extent_fail_max.sql next_e
xtent_fail_size.sql open_cursor_count.sql output.sql priv_users.sql proc_syntax.
sql proc_triggers.sql rac_diag.sql ray_sql.tar useful_scripts.log useful_scripts
.tar useful_scripts2.log useful_scripts3.log 10) "AVG GLOBAL LOCK GET TIME (ms)"
from gv$sysstat b1, gv$sysstat b2, gv$sysstat b3
where b1.name = 'global lock sync gets' and
b2.name = 'global lock async gets' and b3.name = 'global lock get time'
and b1.inrac_
SET ECHO OFF
REM
REM Check for available free space
REM
@save_sqlplus_settings
set linesize 150
set pages 100
set feedback off
set verify off
column db_block_size new_value blocksize noprint

SELECT value db_block_size


FROM v$parameter
WHERE name='db_block_size';
col db_name new_value db_name noprint
select replace(global_name,'.WORLD','') db_name
from global_name
/
col timestamp new_value timestamp noprint
select TO_CHAR(sysdate,'yyyymmddhh24miss') timestamp
from Dual
/
# define DBU_LOG=c:rayfreespace_logs
define DBU_LOG=$HOME/log
TTITLE CENTER 'Tablespace free space' SKIP 1
COLUMN tsname FORMAT a25
COLUMN allocation_type FORMAT A4 TRU HEADING "ALLO|TYPE"
COLUMN extent_management FORMAT A6 TRU HEADING "EXTNT|MNGMNT"
COLUMN contents FORMAT A4 TRU HEADING "CONTENTS"
COLUMN Tot_Size FORMAT 999,999,999 HEADING "ALLOCATED(M)"
COLUMN Tot_Free FORMAT 999,999 HEADING "FREE(M)"
COLUMN Tot_Used FORMAT 999,999,999 HEADING "USED(M)"
-- COLUMN Pct_Used FORMAT 999 HEADING "USED %"
COLUMN Pct_Used FORMAT A6 HEADING "USED %"
COLUMN Fragments FORMAT 99,999 HEADING "FRAGMTS"
COLUMN Large_Ext FORMAT 999,999 HEADING "LARG(M)"
COLUMN IncrmntBytes FORMAT 999,999 HEADING "AUTOEXTEND|MAX ALLOWED|BYTES(M)"
COLUMN Pct_Temp_Actual_Used FORMAT a7 HEAD "PCT|TEMP|ACT|USED"
break on report
compute Sum LABEL SUM of Tot_Size on report
compute Sum LABEL SUM of Tot_free on report
compute Sum LABEL SUM of Tot_Used on report
set feedback off pages 999 trims on
spool &DBU_LOG/freespce_&db_name._&timestamp..log
SELECT a.tablespace_name TSNAME,
DECODE(Sort_Usage.Percent_Used,NULL,ROUND(SUM(a.tots)/1048576,0),(sort_usage.tot
_avail_blocks*dt.block_size)/1048576) Tot_Size,
DECODE(Sort_Usage.Percent_Used,NULL,ROUND((SUM(a.tots)/1048576)-nvl((SUM(a.sumb)
/1048576),0),0),(sort_usage.tot_used_blocks*dt.block_size)/1048576) Tot_Used,
DECODE(Sort_Usage.Percent_Used,NULL,ROUND(SUM(a.sumb)/1048576,0),(sort_usage.tot
_free_blocks*dt.block_size)/1048576) Tot_Free,
-- DECODE(Sort_Usage.Percent_Used,NULL,LPAD(ROUND(((SUM(a.tots)-SUM(a.sumb))/sum
(a.tots))*100,0)||'%',6,CHR(32)),Sort_Usage.Percent_Used||'%') Pct_Used,
DECODE(Sort_Usage.Percent_Used,NULL,LPAD(ROUND(((SUM(a.tots)-SUM(a.sumb))/sum(a.
tots))*100,0)||'%',6,CHR(32)),
LPAD(Sort_Usage.Percent_Used||'%',6,CHR(32))) Pct_Used,
ROUND(SUM(a.largest)/1048576,0) Large_Ext,
SUM(a.chunks) Fragments,
b.contents, b.allocation_type,
b.extent_management,
DECODE(SUM(a.IncrmntBytes),0,0, ROUND(SUM(a.tots)/1048576,0)+round(sum(a.Incrmnt
Bytes/1024/1024),0)) IncrmntBytes
FROM dba_tablespaces dt,
(SELECt tablespace_name, 0 tots, SUM(bytes) sumb,
MAX(bytes) largest, COUNT(*) chunks,0 IncrmntBytes
FROM dba_free_space a
GROUP BY tablespace_name
UNION
SELECT tablespace_name, SUM(bytes) tots, 0, 0, 0, SUM(DECODE(maxbytes,0,0,maxbyt

es-bytes))
FROM dba_data_files f
GROUP BY tablespace_name
UNION
SELECT tablespace_name, SUM(bytes) tots, 0, 0, 0,0
FROM dba_temp_files
GROUP BY tablespace_name) a, dba_tablespaces b,
(
SELECT f.tablespace_name,
DECODE(s.tot_used_blocks,NULL,0,ROUND((s.tot_used_blocks/f.total_blocks)*100,0))
percent_used,
s.tot_avail_blocks,
s.tot_free_blocks,
s.tot_used_blocks
FROM
(
SELECT tablespace_name,
SUM(total_blocks) tot_avail_blocks,
SUM(free_blocks) tot_free_blocks,
SUM(used_blocks) tot_used_blocks
FROM gv$sort_segment
GROUP BY tablespace_name
) s,
(
SELECT tablespace_name, sum(blocks) total_blocks
FROM dba_temp_files
GROUP BY tablespace_name
) f
WHERE f.tablespace_name = s.tablespace_name(+)) SORT_USAGE
WHERE b.tablespace_name = a.tablespace_name
AND b.tablespace_name = dt.tablespace_name
AND b.TABLESPACE_NAME LIKE UPPER('&Tspace'||'%')
AND b.Tablespace_Name = Sort_Usage.Tablespace_name(+)
GROUP BY a.tablespace_name,
Sort_Usage.Percent_Used,
sort_usage.tot_avail_blocks,
dt.block_size,
sort_usage.tot_used_blocks,
sort_usage.tot_free_blocks,
b.contents,
b.allocation_type,
b.extent_management
ORDER BY 1
/
spool off
set linesize 80
@sqlplus_settings
set term on
ttitle off
PROMPT
prompt
prompt Output saved at &DBU_LOG/freespce_&db_name._&timestamp..log
PROMPT
PROMPT
COLUMN PCT_USED DEFAULT
UNDEFINE TSPACE
SET ECHO ON

[LNIDGU1]oracle@idgu1 $ cat pga_uga_per_sess.sql


set echo off
/*===================================================================
||
|| Filename:
pga_uag_sess.sql
||
|| Views:
||
|| Details:
Robert Pang @Oracle Corp
||
|| 19/12/10
Ray Metz
Created as per Robert Pang @ Oracle Corp
||
http://www.idevelopment.info/data/Oracle/DBA_tip
s/Tuning/TUNING_16.shtml
||
===================================================================*/
@@save_sqlplus_settings
SET LINESIZE 145
SET PAGESIZE 9999
COLUMN
COLUMN
USTIFY
COLUMN
USTIFY
COLUMN
RUNC
COLUMN
USTIFY
COLUMN
COLUMN
COLUMN
COLUMN

sid
oracle_username
right
os_username
right
session_program

FORMAT 999
FORMAT a12

HEADING 'SID'
HEADING 'Oracle User'

FORMAT a9

HEADING 'O/S User'

FORMAT a18

HEADING 'Session Program' T

session_machine
right TRUNC
session_pga_memory
session_pga_memory_max
session_uga_memory
session_uga_memory_max

FORMAT a8

HEADING 'Machine'

FORMAT
FORMAT
FORMAT
FORMAT

HEADING
HEADING
HEADING
HEADING

9,999,999,999
9,999,999,999
9,999,999,999
9,999,999,999

'PGA
'PGA
'UGA
'UGA

Memory'
Memory Max'
Memory'
Memory MAX'

SELECT
s.sid
sid
, lpad(s.username,12) oracle_username
, lpad(s.osuser,9)
os_username
, s.program
session_program
, lpad(s.machine,8)
session_machine
, (select ss.value from v$sesstat ss, v$statname sn
where ss.sid = s.sid and
sn.statistic# = ss.statistic# and
sn.name = 'session pga memory')
session_pga_memory
, (select ss.value from v$sesstat ss, v$statname sn
where ss.sid = s.sid and
sn.statistic# = ss.statistic# and
sn.name = 'session pga memory max')
session_pga_memory_max
, (select ss.value from v$sesstat ss, v$statname sn
where ss.sid = s.sid and
sn.statistic# = ss.statistic# and
sn.name = 'session uga memory')
session_uga_memory
, (select ss.value from v$sesstat ss, v$statname sn
where ss.sid = s.sid and
sn.statistic# = ss.statistic# and
sn.name = 'session uga memory max')
session_uga_memory_max
FROM
v$session s
ORDER BY session_pga_memory DESC

/
@@sqlplus_settings

#################
[GRIMIST2]oracle@lonreratesdbu3 $ cat who_dropped.sql
set echo off
/*===================================================================
||
|| Filename:
who_dropped.sql
||
|| Purpose:
DB specific, who dropped an object
||
|| Views:
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
||
===================================================================*/
col userid forma a10
col name forma a16
col tperf forma a20 head 'Time Performed'
col obj$name forma a23
col returncode forma 999999 head 'Return'
col spare1 forma a8 head 'o/s user'
select ac.userid,ac.spare1,aa.name,ac.obj$name,to_char(ac.timestamp,'YYYY-MON-DD
HH24:MI:SS') tperf, ac.returncode
from aud_copy ac, audit_actions aa
where ac.action = aa.action
and ac.action = 12
and ac.obj$name in ('............','...............')
order by ac.timestamp

#########
[GRIMIST2]oracle@lonreratesdbu3 $ cat idle_time.sql
set echo off
@save_sqlplus_settings.sql
set lines 150 verify off
ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';
col Username_LEN new_value USERNAME_LEN noprint
col Program_LEN
new_value PROGRAM_LEN noprint
col sid_serial_LEN
new_value SID_SERIAL_LEN noprint
ACCEPT USERNAME CHAR PROMPT "Enter the username
" default '%'
ACCEPT SID
NUMBER PROMPT "Enter the SID
=>" default 0

===============>
==============

SELECT CASE WHEN MAX(LENGTH(username)) > 50 THEN 'a132' ELSE 'a'||MAX(LENGTH(us


ername)) END USERNAME_LEN,
CASE WHEN MAX(LENGTH(TRIM(program))) > 50 THEN 'a132' ELSE 'a'||MAX(LENG
TH(TRIM(program))) END PROGRAM_LEN,
CASE WHEN MAX(LENGTH(sid||';'||serial#)) > 50 THEN 'a132' ELSE 'a'||MAX(
LENGTH(sid||':'||serial#)) END SID_SERIAL_LEN
FROM
v$session
WHERE username is not null
AND
sid
BETWEEN &SID
AND
DECODE(&SID,0,9999999,&SID)
AND
username
LIKE
UPPER('%&USERNAME.%') ;
col
col
col
col
col

idle_active_time format a16


when_last_active format a22
username format &USERNAME_LEN
program format &PROGRAM_LEN word_wrap
sid_serial format &SID_SERIAL_LEN

SELECT SID||':'||SERIAL# sid_serial,


USERNAME,
osuser,
program,
logon_time,
sysdate-last_call_et/60/60/24 when_last_active,
DECODE(status,'ACTIVE','A ','INACTIVE','I ','KILLED','K ','SNIPED','S ')
||(CASE WHEN EXTRACT (DAY FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CAL
L_ET), 'SECOND')))> 0
THEN
EXTRACT (DAY FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CALL_ET),
'SECOND'))) || 'd '
ELSE NULL
END || CASE
WHEN EXTRACT (HOUR FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CALL
_ET), 'SECOND')))> 0
THEN
EXTRACT (HOUR FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CALL_ET),
'SECOND'))) || 'h '
ELSE NULL
END || CASE
WHEN EXTRACT (MINUTE FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CA
LL_ET), 'SECOND')))> 0
THEN
EXTRACT (MINUTE FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CALL_ET
), 'SECOND'))) || 'm '
ELSE NULL
END || CASE
WHEN EXTRACT (SECOND FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CA
LL_ET), 'SECOND')))> 0
THEN
EXTRACT (SECOND FROM (NUMTODSINTERVAL (SYSDATE - (SYSDATE - LAST_CALL_ET
), 'SECOND'))) || 's '
ELSE NULL
END) AS "IDLE_ACTIVE_TIME"
FROM
V$SESSION
WHERE USERNAME IS NOT NULL
AND
sid
BETWEEN &SID
AND
DECODE(&SID,0,9999999,&SID)
AND
username
LIKE
UPPER('%&USERNAME.%')
ORDER BY LAST_CALL_ET ASC
/

@sqlplus_settings.sql

#################
[GRIMIST2]oracle@lonreratesdbu3 $ cat shared_pool_advise.sql
-- ************************************************
-- Display shared pool advice
-- ************************************************
set lines 132
set pages 999
prompt
prompt The recommendation is normally the Pool Size for the highest value of Est
|Time|Saved|(sec)
prompt If there are multiple records then choose the lowest Pool Size for the hi
ghest value of Est|Time|Saved|(sec)
column
c1
heading 'Pool |Size(M)'
column
c2
heading 'Size|Factor'
column
c3
heading 'Est|LC(M) '
column
c4
heading 'Est LC|Mem. Obj.'
column
c5
heading 'Est|Time|Saved|(sec)'
column
c6
heading 'Est|Parse|Saved|Factor'
column c7
heading 'Est|Object Hits' format 999,999,999,999
SELECT
spa.shared_pool_size_for_estimate c1,
spa.shared_pool_size_factor
c2,
spa.estd_lc_size
c3,
spa.estd_lc_memory_objects
c4,
spa.estd_lc_time_saved
c5,
spa.estd_lc_time_saved_factor
c6,
spa.estd_lc_memory_object_hits
c7,
DECODE(spr.shared_pool_size_for_estimate,NULL,DECODE(spa.shared_pool_size_fac
tor,1,'<====Current Shared Pool Size',NULL),DECODE(spa.shared_pool_size_factor,1
,'<====Current and Recommended Shared Pool Size','<====Recommended Shared Pool S
ize')) Recommendation
FROM
v$shared_pool_advice spa,
(
SELECT MIN(shared_pool_size_for_estimate) shared_pool_size_for_estimate
FROM
v$shared_pool_advice
WHERE estd_lc_time_saved =
(
SELECT MAX(estd_lc_time_saved)
FROM
v$shared_pool_advice)
) spr
WHERE spa.shared_pool_size_for_estimate = spr.shared_pool_size_for_estimate(+)
ORDER BY 1
/
###############
[GRIMIST2]oracle@lonreratesdbu3 $ cat rman_bup_size.sql
set echo off

/*===================================================================
||
|| Filename:
rman_bup_size.sql
||
|| Views:
||
v$rman_backup_job_details
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
|| 06/10/11
Ray Metz
Included CASE statement for bup_to_data_ratio
||
as 0 values caused failure of SQL
|| 20/12/2011 Ray Metz
Included calculation for archivelogs during
||
backup run and excluded some non-essential
||
columns so that output appears on same line
===================================================================*/
@@save_sqlplus_settings
set lines 180
col in_size format a12
col out_size format a12
col comp_ratio format 9999999.99 head 'COMP|RATIO'
col elapsed_seconds format 9999999.99 head 'ELAPSE|SECS'
col time_taken_display format a10 head 'TIME|TAKEN|DISPLAY'
col bup_to_data_ratio format 999999 head 'BUP TO|DATA|RATIO'
col start_time format a25
col end_time format a25
col in_db_incr_and_db_arch_tot format a12 head 'IN_DB|INCR_AND|DB_ARCH_TOT'
col out_db_incr_and_db_arch_tot format a12 head 'OUT_DB|INCR_AND|DB_ARCH_TOT'
col db_in_size_mb format 99,999,999 head 'DB_IN|SIZE_MB'
col db_out_size_mb format 99,999,999 head 'DB_OUT|SIZE_MB'
col arch_in_size_mb format 99,999,999 head 'ARCH_IN|SIZE_MB'
col arch_out_size_mb format 99,999,999 head 'ARCH_OUT|SIZE_MB'
col in_size format a10
col out_size format a10
SELECT ROUND(rbjd1.input_bytes/1024/1024,0) db_in_size_mb,
ROUND(rbjd1.output_bytes/1024/1024,0) db_out_size_mb ,
ROUND(arch_input_bytes/1024/1024,0) arch_in_size_mb,
ROUND(arch_output_bytes/1024/1024,0) arch_out_size_mb,
rbjd1.input_bytes_display in_size,
rbjd1.output_bytes_display out_size ,
CASE
WHEN rbjd1.input_bytes > 0 AND arch_input_bytes > 0
THEN
CASE
WHEN
rbjd1.input_bytes + arch_input_bytes >= 1099511627776
THEN
LPAD(ROUND((rbjd1.input_bytes + arch_input_bytes)/1024/1
024/1024/1024,2)||'T',12,' ')
WHEN
rbjd1.input_bytes + arch_input_bytes >= 1073741824
THEN
LPAD(ROUND((rbjd1.input_bytes + arch_input_bytes)/1024/1
024/1024,2)||'G',12,' ')
WHEN
rbjd1.input_bytes + arch_input_bytes >= 1048576
THEN
LPAD(ROUND((rbjd1.input_bytes + arch_input_bytes)/1024/1
024,2)||'M',12,' ')
WHEN
rbjd1.input_bytes + arch_input_bytes >= 1024
THEN
LPAD(ROUND((rbjd1.input_bytes + arch_input_bytes)/1024,2
)||'K',12,' ')
END

WHEN
THEN

rbjd1.input_bytes > 0
CASE
WHEN
rbjd1.input_bytes >= 1099511627776 THEN
LPAD(ROUND((rbjd1.input_bytes )/1024/1024/1024/1024,2)||

'T',12,' ')
WHEN

rbjd1.input_bytes >= 1073741824


THEN
LPAD(ROUND((rbjd1.input_bytes )/1024/1024/1024,2)||'G',1

WHEN

rbjd1.input_bytes >= 1048576


THEN
LPAD(ROUND((rbjd1.input_bytes)/1024/1024,2)||'M',12,' ')
rbjd1.input_bytes >= 1024
THEN
LPAD(ROUND((rbjd1.input_bytes )/1024,2)||'K',12,' ')

2,' ')
WHEN

END
END in_db_incr_and_db_arch_tot,
CASE
WHEN rbjd1.output_bytes > 0 AND arch_output_bytes > 0
THEN
CASE
WHEN
rbjd1.output_bytes + arch_output_bytes >= 1099511627776
THEN
LPAD(ROUND((rbjd1.output_bytes + arch_output_bytes)/1024
/1024/1024/1024,2)||'T',12,' ')
WHEN
rbjd1.output_bytes + arch_output_bytes >= 1073741824
THEN
LPAD(ROUND((rbjd1.output_bytes + arch_output_bytes)/1024
/1024/1024,2)||'G',12,' ')
WHEN
rbjd1.output_bytes + arch_output_bytes >= 1048576
THEN
LPAD(ROUND((rbjd1.output_bytes + arch_output_bytes)/1024
/1024,2)||'M',12,' ')
WHEN
rbjd1.output_bytes + arch_output_bytes >= 1024
THEN
LPAD(ROUND((rbjd1.output_bytes + arch_output_bytes)/1024
,2)||'K',12,' ')
END
WHEN
rbjd1.output_bytes > 0
THEN
CASE
WHEN
rbjd1.output_bytes >= 1099511627776 THEN
LPAD(ROUND((rbjd1.output_bytes )/1024/1024/1024/1024,2)|
|'T',12,' ')
WHEN
rbjd1.output_bytes >= 1073741824
THEN
LPAD(ROUND((rbjd1.output_bytes )/1024/1024/1024,2)||'G',
12,' ')
WHEN
rbjd1.output_bytes >= 1048576
THEN
LPAD(ROUND((rbjd1.output_bytes)/1024/1024,2)||'M',12,' '
)
WHEN
rbjd1.output_bytes >= 1024
THEN
LPAD(ROUND((rbjd1.output_bytes )/1024,2)||'K',12,' ')
END
END out_db_incr_and_db_arch_tot,
CASE
WHEN rbjd1.input_bytes = 0 THEN 0
WHEN
rbjd1.output_bytes = 0 THEN 0
ELSE
ROUND(rbjd1.input_bytes/rbjd1.output_bytes,0)
END bup_to_data_ratio,
to_char(rbjd1.start_time,'DY dd-mon-yyyy hh24:mi') start_time,
to_char(rbjd1.end_time,'DY dd-mon-yyyy hh24:mi') end_time,
ROUND(rbjd1.elapsed_seconds/3600,2) elapsed_seconds,
rbjd1.time_taken_display
FROM
v$rman_backup_job_details
rbjd1,
(

SELECT rbjd3.start_time,
rbjd3.end_time,
SUM(rbjd2.input_bytes) arch_input_bytes,
SUM(rbjd2.output_bytes) arch_output_bytes
FROM
v$rman_backup_job_details
rbjd2,
(
SELECT start_time,
end_time
FROM
v$rman_backup_job_details
WHERE input_type='DB INCR'
)
rbjd3
WHERE rbjd2.input_type='ARCHIVELOG'
AND
rbjd2.start_time >= rbjd3.start_time
AND
rbjd2.end_time <= rbjd3.end_time
GROUP BY rbjd3.start_time,
rbjd3.end_time) rbjd4
WHERE rbjd1.input_type='DB INCR'
AND
rbjd1.start_time
>=
rbjd4.start_time(+)
AND
rbjd1.end_time
<=
rbjd4.end_time(+)
ORDER BY rbjd1.session_key
/
@@sqlplus_settings
set echo on
################
Library cache
[GRIMIST2]oracle@lonreratesdbu3 $ cat check_oaf_ret.sql
set echo off
@@save_sqlplus_settings
select TIMESTAMP
from aud_statistics
where rec_type= 'EX10';
@@sqlplus_settings
set echo on
[GRIMIST2]oracle@lonreratesdbu3 $ cat libcache_test.sql
create or replace procedure backup.test_kgllk (l_sleep in boolean , l_compile in
boolean)
as
begin
if (l_sleep ) then
sys.dbms_lock.sleep(60);
elsif (l_compile ) then
execute immediate 'alter procedure test_kgllk compile';
end if;
end;
/
--In this test case above, we create a procedure and it accepts two boolean para
meters: sleep and compile. Passing true to first argument will enable the proced
ure to sleep for a minute and passing true for the second argument will enable t
he procedure to recompile itself.
-- Let's create two sessions in the database and then execute them as below.
--Session #1: exec test_kgllk ( true, false); Sleep for 1 minutes and no compile
--Session #2: exec test_kgllk ( false, true); No sleep,but compile..

--At this point both sessions are waiting. Following SQL can be used to print se
ssion wait details.
select
distinct
ses.ksusenum sid, ses.ksuseser serial#, ses.ksuudlna username,ses.ksuseunm ma
chine,
ob.kglnaown obj_owner, ob.kglnaobj obj_name
,pn.kglpncnt pin_cnt, pn.kglpnmod pin_mode, pn.kglpnreq pin_req
, w.state, w.event, w.wait_Time, w.seconds_in_Wait
-- lk.kglnaobj, lk.user_name, lk.kgllksnm,
--,lk.kgllkhdl,lk.kglhdpar
--,trim(lk.kgllkcnt) lock_cnt, lk.kgllkmod lock_mode, lk.kgllkreq lock_req,
--,lk.kgllkpns, lk.kgllkpnc,pn.kglpnhdl
from
x$kglpn pn, x$kglob ob,x$ksuse ses
, v$session_wait w
where pn.kglpnhdl in
(select kglpnhdl from x$kglpn where kglpnreq >0 )
and ob.kglhdadr = pn.kglpnhdl
and pn.kglpnuse = ses.addr
and w.sid = ses.indx
order by seconds_in_wait desc
/
-- Output of above SQL is:
-- 1. Session 268 (session #1) is sleeping while holding library cache pin on
test_kgllk object (waiting on PL/SQL lock timer more accurately).
-- 2. Session 313 is holding library cache pin in mode 2 and waiting for libra
ry cache pin in mode 3.
-- Obviously, session 313 is waiting for session 268 to release library cache pi
ns. Since session 268 is executing, session 313 should not be allowed to modify
test_kgllk library cache object. Thats exactly why library cache pins are needed.
-- Adding another session to this mix..
-- Let's add one more session as below
exec test_kgllk (false, true);
-- Well, no surprise there. New session 442 also waiting for library cache pin.
But, notice the request mode for session 442. It is 2. Session 442 needs that li
brary cache pin in share mode to start execution. But 313 has already requested
that library cache pin in mode 3. A queue is building up here. Many processes ca
n queue behind session 313 at this point leading to an hung instance.
-- library cache locks..
-- Let's execute same package but both with same parameters.
-- Session #1: exec test_kgllk(false, true);
-- Session #2: exec test_kgllk(false, true);
-- Rerunning above query tells us that session 313 is waiting for the self. Even
tually, this will lead library cache pin self deadlock.
-- Wait, what happened to session #2? It is not visible in x$kglpn. Querying v$s

ession_wait shows that Session #2 is waiting for library cache lock. We will run
yet another query against x$kgllk to see library cache lock waits.
-- Querying x$kgllk with the query below:
select
distinct
ses.ksusenum sid, ses.ksuseser serial#, ses.ksuudlna username,KSUSEMNM module
,
ob.kglnaown obj_owner, ob.kglnaobj obj_name
,lk.kgllkcnt lck_cnt, lk.kgllkmod lock_mode, lk.kgllkreq lock_req
, w.state, w.event, w.wait_Time, w.seconds_in_Wait
from
x$kgllk lk, x$kglob ob,x$ksuse ses
, v$session_wait w
where lk.kgllkhdl in
(select kgllkhdl from x$kgllk where kgllkreq >0 )
and ob.kglhdadr = lk.kgllkhdl
and lk.kgllkuse = ses.addr
and w.sid = ses.indx
order by seconds_in_wait desc
/
-- Session 313 is holding library cache lock on that object in mode 3 and sessio
n 268 is requesting lock on that library cache object in mode 2. So, session 268
is waiting for library cache lock while session 313 is waiting for library cach
e pin (self ). Again, point here is that session 268 is trying to access library
cache object and need to acquire library cache lock in correct mode. That libra
ry cache lock is not available leading to a wait.
-- Complete script can be downloaded from my script archive.

############
[GRIMIST2]oracle@lonreratesdbu3 $ cat dbms_space_used.sql
set echo off
/*===================================================================
||
|| Filename:
dbms_space_used.sql
||
|| Views:
None - pl/sql block
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
||
===================================================================*/
@@save_sqlplus_settings
set serverout on size 999999 verify off
ACCEPT segment_owner
CHAR PROMPT "Enter the object owner ===================
=====> " default '%'
ACCEPT segment_name
CHAR PROMPT "Enter the object name ===================
=====> " default '%'

ACCEPT segment_type
=====> " default '%'

CHAR PROMPT "Enter the object type

===================

DECLARE
c_segment_owner
varchar2(30):='&segment_owner';-- Schema name of the seg
ment to be analyzed
c_segment_name
varchar2(30):='&segment_name';-- Name of the segment to
be analyzed
c_partition_name
varchar2(30);-- Partition name of the segment to be anal
yzed
c_segment_type
varchar2(30):='&segment_type';-- Type of the segment to
be analyzed (TABLE, INDEX, or CLUSTER)
n_unformatted_blocks
NUMBER;-- Total number of blocks that are unformatted
n_unformatted_bytes
NUMBER;-- Total number of bytes that are unformatted
n_fs1_blocks
NUMBER;-- Number of blocks that has at least 0 to 25% fr
ee space
n_fs1_bytes
NUMBER;-- Number of bytes that has at least 0 to 25% fre
e space
n_fs2_blocks
NUMBER;-- Number of blocks that has at least 25 to 50% f
ree space
n_fs2_bytes
NUMBER;-- Number of bytes that has at least 25 to 50% fr
ee space
n_fs3_blocks
NUMBER;-- Number of blocks that has at least 50 to 75% f
ree space
n_fs3_bytes
NUMBER;-- Number of bytes that has at least 50 to 75% fr
ee space
n_fs4_blocks
NUMBER;-- Number of blocks that has at least 75 to 100%
free space
n_fs4_bytes
NUMBER;-- Number of bytes that has at least 75 to 100% f
ree space
n_full_blocks
NUMBER;-- Total number of blocks that are full in the se
gment
n_full_bytes
NUMBER;-- Total number of bytes that are full in the seg
ment
begin
dbms_space.space_usage(
UPPER(c_segment_owner),
UPPER(c_segment_name),
UPPER(c_segment_type),
n_unformatted_blocks,
n_unformatted_bytes,
n_fs1_blocks,
n_fs1_bytes,
n_fs2_blocks,
n_fs2_bytes,
n_fs3_blocks,
n_fs3_bytes,
n_fs4_blocks,
n_fs4_bytes,
n_full_blocks,
n_full_bytes);
dbms_output.put_line('SEGMENT OWNER
dbms_output.put_line('SEGMENT NAME
dbms_output.put_line('PARTITION NAME
dbms_output.put_line('SEGMENT TYPE
dbms_output.put_line('UNFORMATTED BLOCKS
dbms_output.put_line('UNFORMATTED BYTES

:
:
:
:
:
:

'||UPPER(c_segment_owner));
'||UPPER(c_segment_name));
'||UPPER(c_partition_name));
'||UPPER(c_segment_Type));
'||n_unformatted_blocks);
'||n_unformatted_bytes);

dbms_output.put_line('BLOCKS 0 to
dbms_output.put_line('BYTES 0 to
dbms_output.put_line('BLOCKS 25 to
dbms_output.put_line('BYTES 25 to
dbms_output.put_line('BLOCKS 50 to
dbms_output.put_line('BYTES 50 to
dbms_output.put_line('BLOCKS 75 to
dbms_output.put_line('BYTES 75 to
dbms_output.put_line('FULL BLOCKS
dbms_output.put_line('FULL BYTES
end;
/

25%
25%
50%
50%
75%
75%
100%
100%

FREE
FREE
FREE
FREE
FREE
FREE
FREE
FREE

:
:
:
:
:
:
:
:
:
:

'||n_fs1_blocks);
'||n_fs1_bytes);
'||n_fs2_blocks);
'||n_fs2_bytes);
'||n_fs3_blocks);
'||n_fs3_bytes);
'||n_fs4_blocks);
'||n_fs4_bytes);
'||n_full_blocks);
'||n_full_bytes);

@sqlplus_settings
#############
[GRIMIST2]oracle@lonreratesdbu3 $ cat rac_diag.sql
set feedback off
column timecol new_value timestamp
column spool_extension new_value suffix
select to_char(sysdate,'Mondd_hhmi') timecol,
'.out' spool_extension from sys.dual;
column output new_value dbname
select value || '_' output
from v$parameter where name = 'db_name';
spool racdiag_&&dbname&tamp&&suffix
set lines 200
set pagesize 35
set trim on
set trims on
alter session set nls_date_format = 'MON-DD-YYYY HH24:MI:SS';
alter session set timed_statistics = true;
set feedback on
select to_char(sysdate) time from dual;
set numwidth 5
column host_name format a20 tru
select inst_id, instance_name, host_name, version, status, startup_time
from gv$instance
order by inst_id;
set echo on
-- Taking Hang Analyze dumps
-- This may take a little while...
oradebug setmypid
oradebug unlimit
oradebug -g all hanganalyze 3
-- This part may take the longest, you can monitor bdump or udump to see if the
-- file is being generated.
oradebug -g all dump systemstate 266
------

WAITING SESSIONS:
The entries that are shown at the top are the sessions that have
waited the longest amount of time that are waiting for non-idle wait
events (event column). You can research and find out what the wait
event indicates (along with its parameters) by checking the Oracle

-- Server Reference Manual or look for any known issues or documentation


-- by searching Metalink for the event name in the search bar. Example
-- (include single quotes): [ 'buffer busy due to global cache' ].
-- Metalink and/or the Server Reference Manual should return some useful
-- information on each type of wait event. The inst_id column shows the
-- instance where the session resides and the SID is the unique identifier
-- for the session (gv$session). The p1, p2, and p3 columns will show
-- event specific information that may be important to debug the problem.
-- To find out what the p1, p2, and p3 indicates see the next section.
-- Items with wait_time of anything other than 0 indicate we do not know
-- how long these sessions have been waiting.
-set numwidth 10
column state format a7 tru
column event format a25 tru
column last_sql format a40 tru
select sw.inst_id, sw.sid, sw.state, sw.event, sw.seconds_in_wait seconds,
sw.p1, sw.p2, sw.p3, sa.sql_text last_sql
from gv$session_wait sw, gv$session s, gv$sqlarea sa
where sw.event not in
('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and sw.seconds_in_wait > 0
and (sw.inst_id = s.inst_id and sw.sid = s.sid)
and (s.inst_id = sa.inst_id and s.sql_address = sa.address)
order by seconds desc;
-- EVENT PARAMETER LOOKUP:
-- This section will give a description of the parameter names of the
-- events seen in the last section. p1test is the parameter value for
-- p1 in the WAITING SESSIONS section while p2text is the parameter
-- value for p3 and p3 text is the parameter value for p3. The
-- parameter values in the first section can be helpful for debugging
-- the wait event.
-column event format a30 tru
column p1text format a25 tru
column p2text format a25 tru
column p3text format a25 tru
select distinct event, p1text, p2text, p3text
from gv$session_wait sw
where sw.event not in ('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and seconds_in_wait > 0
order by event;
-------

GES LOCK BLOCKERS:


This section will show us any sessions that are holding locks that
are blocking other users. The inst_id will show us the instance that
the session resides on while the sid will be a unique identifier for
the session. The grant_level will show us how the GES lock is granted to
the user. The request_level will show us what status we are trying to obtain.

-- The lockstate column will show us what status the lock is in. The last column
-- shows how long this session has been waiting.
-set numwidth 5
column state format a16 tru;
column event format a30 tru;
select dl.inst_id, s.sid, p.spid, dl.resource_name1,
decode(substr(dl.grant_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as grant_level,
decode(substr(dl.request_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as request_level,
decode(substr(dl.state,1,8),'KJUSERGR','Granted','KJUSEROP','Opening',
'KJUSERCA','Canceling','KJUSERCV','Converting') as state,
s.sid, sw.event, sw.seconds_in_wait sec
from gv$ges_enqueue dl, gv$process p, gv$session s, gv$session_wait sw
where blocker = 1
and (dl.inst_id = p.inst_id and dl.pid = p.spid)
and (p.inst_id = s.inst_id and p.addr = s.paddr)
and (s.inst_id = sw.inst_id and s.sid = sw.sid)
order by sw.seconds_in_wait desc;
-- GES LOCK WAITERS:
-- This section will show us any sessions that are waiting for locks that
-- are blocked by other users. The inst_id will show us the instance that
-- the session resides on while the sid will be a unique identifier for
-- the session. The grant_level will show us how the GES lock is granted to
-- the user. The request_level will show us what status we are trying to obtain.
-- The lockstate column will show us what status the lock is in. The last column
-- shows how long this session has been waiting.
-set numwidth 5
column state format a16 tru;
column event format a30 tru;
select dl.inst_id, s.sid, p.spid, dl.resource_name1,
decode(substr(dl.grant_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as grant_level,
decode(substr(dl.request_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',
'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',
'KJUSEREX','Exclusive',request_level) as request_level,
decode(substr(dl.state,1,8),'KJUSERGR','Granted','KJUSEROP','Opening',
'KJUSERCA','Cancelling','KJUSERCV','Converting') as state,
s.sid, sw.event, sw.seconds_in_wait sec
from gv$ges_enqueue dl, gv$process p, gv$session s, gv$session_wait sw
where blocked = 1
and (dl.inst_id = p.inst_id and dl.pid = p.spid)
and (p.inst_id = s.inst_id and p.addr = s.paddr)
and (s.inst_id = sw.inst_id and s.sid = sw.sid)
order by sw.seconds_in_wait desc;
-----s
---

LOCAL ENQUEUES:
This section will show us if there are any local
show us the instance that the session resides on
unique identifier for. The addr column will show
will show the lock type. The id1 and id2 columns
for the lock type.

enqueues. The inst_id will


while the sid will be a
the lock address. The type
will show specific parameter

set numwidth 12
column event format a12 tru
select l.inst_id, l.sid, l.addr, l.type, l.id1, l.id2,
decode(l.block,0,'blocked',1,'blocking',2,'global') block,
sw.event, sw.seconds_in_wait sec
from gv$lock l, gv$session_wait sw
where (l.sid = sw.sid and l.inst_id = sw.inst_id)
and l.block in (0,1)
order by l.type, l.inst_id, l.sid;
-- LATCH HOLDERS:
-- If there is latch contention or 'latch free' wait events in the WAITING
-- SESSIONS section we will need to find out which proceseses are holding
-- latches. The inst_id will show us the instance that the session resides
-- on while the sid will be a unique identifier for. The username column
-- will show the session's username. The os_user column will show the os
-- user that the user logged in as. The name column will show us the type
-- of latch being waited on. You can search Metalink for the latch name in
-- the search bar. Example (include single quotes):
-- [ 'library cache' latch ]. Metalink should return some useful information
-- on the type of latch.
-set numwidth 5
select distinct lh.inst_id, s.sid, s.username, p.username os_user, lh.name
from gv$latchholder lh, gv$session s, gv$process p
where (lh.sid = s.sid and lh.inst_id = s.inst_id)
and (s.inst_id = p.inst_id and s.paddr = p.addr)
order by lh.inst_id, s.sid;
-- LATCH STATS:
-- This view will show us latches with less than optimal hit ratios
-- The inst_id will show us the instance for the particular latch. The
-- latch_name column will show us the type of latch. You can search Metalink
-- for the latch name in the search bar. Example (include single quotes):
-- [ 'library cache' latch ]. Metalink should return some useful information
-- on the type of latch. The hit_ratio shows the percentage of time we
-- successfully acquired the latch.
-column latch_name format a30 tru
select inst_id, name latch_name,
round((gets-misses)/decode(gets,0,1,gets),3) hit_ratio,
round(sleeps/decode(misses,0,1,misses),3) "SLEEPS/MISS"
from gv$latch
where round((gets-misses)/decode(gets,0,1,gets),3) < .99
and gets != 0
order by round((gets-misses)/decode(gets,0,1,gets),3);
-- No Wait Latches:
-select inst_id, name latch_name,
round((immediate_gets/(immediate_gets+immediate_misses)), 3) hit_ratio,
round(sleeps/decode(immediate_misses,0,1,immediate_misses),3) "SLEEPS/MISS"
from gv$latch
where round((immediate_gets/(immediate_gets+immediate_misses)), 3) < .99
and immediate_gets + immediate_misses > 0
order by round((immediate_gets/(immediate_gets+immediate_misses)), 3);
-- GLOBAL CACHE CR PERFORMANCE
-- This shows the average latency of a consistent block request.
-- AVG CR BLOCK RECEIVE TIME should typically be about 15 milliseconds depending

-- on your system configuration and volume, is the average latency of a


-- consistent-read request round-trip from the requesting instance to the holdin
g
-- instance and back to the requesting instance. If your CPU has limited idle ti
me
-- and your system typically processes long-running queries, then the latency ma
y
-- be higher. However, it is possible to have an average latency of less than on
e
-- millisecond with User-mode IPC. Latency can be influenced by a high value for
-- the DB_MULTI_BLOCK_READ_COUNT parameter. This is because a requesting process
-- can issue more than one request for a block depending on the setting of this
-- parameter. Correspondingly, the requesting process may wait longer. Also chec
k
-- interconnect badwidth, OS tcp settings, and OS udp settings if
-- AVG CR BLOCK RECEIVE TIME is high.
-set numwidth 20
column "AVG CR BLOCK RECEIVE TIME (ms)" format 9999999.9
select b1.inst_id, b2.value "GCS CR BLOCKS RECEIVED",
b1.value "GCS CR BLOCK RECEIVE TIME",
((b1.value / b2.value) a.sql active.sql active_rbs.sql active_temp.sql activep.s
ql activew.sql applied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm
_create_dg_ext_red.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_powe
r.sql asm_drop_disk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_
logs_applied.sql check_logs_recd.sql check_primary_stus.sql column_settings.sql
concat_sqltext.sql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql crea
te_cdrs_user.sql create_indexes_restore.sql create_indexes_restore2.sql create_s
cripts.ksh create_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql
desc.sql dict_temp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sq
l epoc.sql explain2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.
sql freeblocks.sql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 g
et_extents.sql get_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glo
gin.sql how_to_start_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage
.sql lockers.sql locks.sql locks2.sql long_runners.sql long_running_jobs.sql lon
gops.sql minshpool.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monito
r_temp_space.sql next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_
size.sql open_cursor_count.sql output.sql priv_users.sql proc_syntax.sql proc_tr
iggers.sql rac_diag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful
_scripts2.log useful_scripts3.log 10) "AVG CR BLOCK RECEIVE TIME (ms)"
from gv$sysstat b1, gv$sysstat b2
where b1.name = 'global cache cr block receive time' and
b2.name = 'global cache cr blocks received' and b1.inst_id = b2.inst_id ;
-- GLOBAL CACHE LOCK PERFORMANCE
-- This shows the average global enqueue get time.
-- Typically AVG GLOBAL LOCK GET TIME should be 20-30 milliseconds. the elapsed
-- time for a get includes the allocation and initialization of a new global
-- enqueue. If the average global enqueue get (global cache get time) or average
-- global enqueue conversion times are excessive, then your system may be
-- experiencing timeouts. See the 'WAITING SESSIONS', 'GES LOCK BLOCKERS',
-- 'GES LOCK WAITERS', and 'TOP 10 WAIT EVENTS ON SYSTEM' sections if the
-- AVG GLOBAL LOCK GET TIME is high.
-set numwidth 20
column "AVG GLOBAL LOCK GET TIME (ms)" format 9999999.9
select b1.inst_id, (b1.value + b2.value) "GLOBAL LOCK GETS",
b3.value "GLOBAL LOCK GET TIME",
(b3.value / (b1.value + b2.value) a.sql active.sql active_rbs.sql active_temp.sq
l activep.sql activew.sql applied_logs.sql archivelog_histogram.sql asm_add_disk

_dg.sql asm_create_dg_ext_red.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg


_rebal_power.sql asm_drop_disk_dg.sql asm_used_space.sql blockers.sql buffer_map
.sql check_logs_applied.sql check_logs_recd.sql check_primary_stus.sql column_se
ttings.sql concat_sqltext.sql connect.sql connect_setup.sql cpu_usage.sql cr_inv
al.sql create_cdrs_user.sql create_indexes_restore.sql create_indexes_restore2.s
ql create_scripts.ksh create_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_b
ackups.sql desc.sql dict_temp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user
_cashown.sql epoc.sql explain2.sql explain3.sql file_ts.sql free_used_blocks.sql
freeblock.sql freeblocks.sql freeblocksts.sql freespce.sql freespce734.sql free
spce_pre8 get_extents.sql get_part.sql get_set_newnames.sql get_sql.sql get_sqlt
ext.sql glogin.sql how_to_start_auto_recovery.sql indcol.sql lib_locks.sql local
_temp_usage.sql lockers.sql locks.sql locks2.sql long_runners.sql long_running_j
obs.sql longops.sql minshpool.sql mon_locks.sql mon_rec_proc.sql mon_rec_process
.sql monitor_temp_space.sql next_extent_fail.sql next_extent_fail_max.sql next_e
xtent_fail_size.sql open_cursor_count.sql output.sql priv_users.sql proc_syntax.
sql proc_triggers.sql rac_diag.sql ray_sql.tar useful_scripts.log useful_scripts
.tar useful_scripts2.log useful_scripts3.log 10) "AVG GLOBAL LOCK GET TIME (ms)"
from gv$sysstat b1, gv$sysstat b2, gv$sysstat b3
where b1.name = 'global lock sync gets' and
b2.name = 'global lock async gets' and b3.name = 'global lock get time'
and b1.inst_id = b2.inst_id and b2.inst_id = b3.inst_id;
-- RESOURCE USAGE
-- This section will show how much of our resources we have used.
-set numwidth 8
select inst_id, resource_name, current_utilization, max_utilization,
initial_allocation
from gv$resource_limit
where max_utilization > 0
order by inst_id, resource_name;
-- DLM TRAFFIC INFORMATION
-- This section shows how many tickets are available in the DLM. If the
-- TCKT_WAIT columns says "YES" then we have run out of DLM tickets which could
-- cause a DLM hang. Make sure that you also have enough TCKT_AVAIL.
-set numwidth 5
select a.sql active.sql active_rbs.sql active_temp.sql activep.sql activew.sql a
pplied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm_create_dg_ext_r
ed.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_power.sql asm_drop_d
isk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_logs_applied.sql
check_logs_recd.sql check_primary_stus.sql column_settings.sql concat_sqltext.s
ql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql create_cdrs_user.sql
create_indexes_restore.sql create_indexes_restore2.sql create_scripts.ksh creat
e_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql desc.sql dict_te
mp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sql epoc.sql expla
in2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.sql freeblocks.s
ql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 get_extents.sql g
et_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glogin.sql how_to_s
tart_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage.sql lockers.sql
locks.sql locks2.sql long_runners.sql long_running_jobs.sql longops.sql minshpo
ol.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monitor_temp_space.sql
next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_size.sql open_cu
rsor_count.sql output.sql priv_users.sql proc_syntax.sql proc_triggers.sql rac_d
iag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful_scripts2.log us
eful_scripts3.log from gv$dlm_traffic_controller
order by TCKT_AVAIL;
-- DLM MISC

-set numwidth 10
select a.sql active.sql active_rbs.sql active_temp.sql activep.sql activew.sql a
pplied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm_create_dg_ext_r
ed.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_power.sql asm_drop_d
isk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_logs_applied.sql
check_logs_recd.sql check_primary_stus.sql column_settings.sql concat_sqltext.s
ql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql create_cdrs_user.sql
create_indexes_restore.sql create_indexes_restore2.sql create_scripts.ksh creat
e_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql desc.sql dict_te
mp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sql epoc.sql expla
in2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.sql freeblocks.s
ql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 get_extents.sql g
et_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glogin.sql how_to_s
tart_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage.sql lockers.sql
locks.sql locks2.sql long_runners.sql long_running_jobs.sql longops.sql minshpo
ol.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monitor_temp_space.sql
next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_size.sql open_cu
rsor_count.sql output.sql priv_users.sql proc_syntax.sql proc_triggers.sql rac_d
iag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful_scripts2.log us
eful_scripts3.log from gv$dlm_misc;
-- LOCK CONVERSION DETAIL:
-- This view shows the types of lock conversion being done on each instance.
-select a.sql active.sql active_rbs.sql active_temp.sql activep.sql activew.sql a
pplied_logs.sql archivelog_histogram.sql asm_add_disk_dg.sql asm_create_dg_ext_r
ed.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg_rebal_power.sql asm_drop_d
isk_dg.sql asm_used_space.sql blockers.sql buffer_map.sql check_logs_applied.sql
check_logs_recd.sql check_primary_stus.sql column_settings.sql concat_sqltext.s
ql connect.sql connect_setup.sql cpu_usage.sql cr_inval.sql create_cdrs_user.sql
create_indexes_restore.sql create_indexes_restore2.sql create_scripts.ksh creat
e_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_backups.sql desc.sql dict_te
mp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user_cashown.sql epoc.sql expla
in2.sql explain3.sql file_ts.sql free_used_blocks.sql freeblock.sql freeblocks.s
ql freeblocksts.sql freespce.sql freespce734.sql freespce_pre8 get_extents.sql g
et_part.sql get_set_newnames.sql get_sql.sql get_sqltext.sql glogin.sql how_to_s
tart_auto_recovery.sql indcol.sql lib_locks.sql local_temp_usage.sql lockers.sql
locks.sql locks2.sql long_runners.sql long_running_jobs.sql longops.sql minshpo
ol.sql mon_locks.sql mon_rec_proc.sql mon_rec_process.sql monitor_temp_space.sql
next_extent_fail.sql next_extent_fail_max.sql next_extent_fail_size.sql open_cu
rsor_count.sql output.sql priv_users.sql proc_syntax.sql proc_triggers.sql rac_d
iag.sql ray_sql.tar useful_scripts.log useful_scripts.tar useful_scripts2.log us
eful_scripts3.log from gv$lock_activity;
-- TOP 10 WRITE PINGING/FUSION OBJECTS
-- This view shows the top 10 objects for write pings accross instances.
-- The inst_id column shows the node that the block was pinged on. The name
-- column shows the object name of the offending object. The file# shows the
-- offending file number (gc_files_to_locks). The STATUS column will show the
-- current status of the pinged block. The READ_PINGS will show us read converts
-- and the WRITE_PINGS will show us objects with write converts. Any rows that
-- show up are objects that are concurrently accessed across more than 1 instanc
e.
-set numwidth 8
column name format a20 tru
column kind format a10 tru
select inst_id, name, kind, file#, status, BLOCKS,
READ_PINGS, WRITE_PINGS

from (select p.inst_id, p.name, p.kind, p.file#, p.status,


count(p.block#) BLOCKS, sum(p.forced_reads) READ_PINGS,
sum(p.forced_writes) WRITE_PINGS
from gv$ping p, gv$datafile df
where p.file# = df.file# (+)
group by p.inst_id, p.name, p.kind, p.file#, p.status
order by sum(p.forced_writes) desc)
where rownum < 11
order by WRITE_PINGS desc;
-- TOP 10 READ PINGING/FUSION OBJECTS
-- This view shows the top 10 objects for read pings. The inst_id column shows
-- the node that the block was pinged on. The name column shows the object name
-- of the offending object. The file# shows the offending file number
-- (gc_files_to_locks). The STATUS column will show the current status of the
-- pinged block. The READ_PINGS will show us read converts and the WRITE_PINGS
-- will show us objects with write converts. Any rows that show up are objects
-- that are concurrently accessed across more than 1 instance.
-set numwidth 8
column name format a20 tru
column kind format a10 tru
select inst_id, name, kind, file#, status, BLOCKS,
READ_PINGS, WRITE_PINGS
from (select p.inst_id, p.name, p.kind, p.file#, p.status,
count(p.block#) BLOCKS, sum(p.forced_reads) READ_PINGS,
sum(p.forced_writes) WRITE_PINGS
from gv$ping p, gv$datafile df
where p.file# = df.file# (+)
group by p.inst_id, p.name, p.kind, p.file#, p.status
order by sum(p.forced_reads) desc)
where rownum < 11
order by READ_PINGS desc;
-- TOP 10 FALSE PINGING OBJECTS
-- This view shows the top 10 objects for false pings. This can be avoided by
-- better gc_files_to_locks configuration. The inst_id column shows the node
-- that the block was pinged on. The name column shows the object name of the
-- offending object. The file# shows the offending file number
-- (gc_files_to_locks). The STATUS column will show the current status of the
-- pinged block. The READ_PINGS will show us read converts and the WRITE_PINGS
-- will show us objects with write converts. Any rows that show up are objects
-- that are concurrently accessed across more than 1 instance.
-set numwidth 8
column name format a20 tru
column kind format a10 tru
select inst_id, name, kind, file#, status, BLOCKS,
READ_PINGS, WRITE_PINGS
from (select p.inst_id, p.name, p.kind, p.file#, p.status,
count(p.block#) BLOCKS, sum(p.forced_reads) READ_PINGS,
sum(p.forced_writes) WRITE_PINGS
from gv$false_ping p, gv$datafile df
where p.file# = df.file# (+)
group by p.inst_id, p.name, p.kind, p.file#, p.status
order by sum(p.forced_writes) desc)
where rownum < 11
order by WRITE_PINGS desc;
-- INITIALIZATION PARAMETERS:

-- Non-default init parameters for each node.


-set numwidth 5
column name format a30 tru
column value format a50 wra
column description format a60 tru
select inst_id, name, value, description
from gv$parameter
where isdefault = 'FALSE'
order by inst_id, name;
-- TOP 10 WAIT EVENTS ON SYSTEM
-- This view will provide a summary of the top wait events in the db.
-set numwidth 10
column event format a25 tru
select inst_id, event, time_waited, total_waits, total_timeouts
from (select inst_id, event, time_waited, total_waits, total_timeouts
from gv$system_event where event not in ('rdbms ipc message','smon timer',
'pmon timer', 'SQL*Net message from client','lock manager wait for remote messag
e',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
order by time_waited desc)
where rownum < 11
order by time_waited desc;
-- SESSION/PROCESS REFERENCE:
-- This section is very important for most of the above sections to find out
-- which user/os_user/process is identified to which session/process.
-set numwidth 7
column event format a30 tru
column program format a25 tru
column username format a15 tru
select p.inst_id, s.sid, s.serial#, p.pid, p.spid, p.program, s.username,
p.username os_user, sw.event, sw.seconds_in_wait sec
from gv$process p, gv$session s, gv$session_wait sw
where (p.inst_id = s.inst_id and p.addr = s.paddr)
and (s.inst_id = sw.inst_id and s.sid = sw.sid)
order by p.inst_id, s.sid;
-- SYSTEM STATISTICS:
-- All System Stats with values of > 0. These can be referenced in the
-- Server Reference Manual
-set numwidth 5
column name format a60 tru
column value format 9999999999999999999999999
select inst_id, name, value
from gv$sysstat
where value > 0
order by inst_id, name;
-- CURRENT SQL FOR WAITING SESSIONS:
-- Current SQL for any session in the WAITING SESSIONS list
-set numwidth 5

column sql format a80 wra


select sw.inst_id, sw.sid, sw.seconds_in_wait sec, sa.sql_text sql
from gv$session_wait sw, gv$session s, gv$sqlarea sa
where sw.sid = s.sid (+)
and sw.inst_id = s.inst_id (+)
and s.sql_address = sa.address
and sw.event not in ('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and seconds_in_wait > 0
order by sw.seconds_in_wait desc;
-- Taking Hang Analyze dumps
-- This may take a little while...
oradebug setmypid
oradebug unlimit
oradebug -g all hanganalyze 3
-- This part may take the longest, you can monitor bdump or udump to see if the
-- file is being generated.
oradebug -g all dump systemstate 266
set echo off
select to_char(sysdate) time from dual;
spool off
-- --------------------------------------------------------------------------Prompt;
Prompt racdiag output files have been written to:;
Prompt;
host pwd
Prompt alert log and trace files are located in:;
column host_name format a12 tru
column name format a20 tru
column value format a60 tru
select distinct i.host_name, p.name, p.value
from gv$instance i, gv$parameter p
where p.inst_id = i.inst_id (+)
and p.name like '%_dump_dest'
and p.name != 'core_dump_dest';
- - - - - - - - - - - - - - - - Script ends here - - - - - - - - - - - - - - - Sample Output:
-------------TIME
-------------------AUG-11-2001 12:06:36
1 row selected.
INST_ID INSTANCE_NAME HOST_NAME VERSION STATUS STARTUP_TIME

------- ---------------- -------------------- -------------- ------- ----------1 V9201 opcbsol1 9.2.0.1.0 OPEN AUG-01-2002
2 V9202 opcbsol2 9.2.0.1.0 OPEN JUL-09-2002
2 rows selected.
SQL>
SQL> -- Taking Hanganalyze Dumps
SQL> -- This may take a little while...
SQL> oradebug setmypid
Statement processed.
SQL> oradebug unlimit
Statement processed.
SQL> oradebug setinst all
Statement processed.
SQL> oradebug -g def hanganalyze 3
Hang Analysis in /u02/32bit/app/oracle/admin/V9232/bdump/v92321_diag_29495.trc
SQL>
SQL> -- WAITING SESSIONS:
SQL> -- The entries that are shown at the top are the sessions that have
SQL> -- waited the longest amount of time that are waiting for non-idle wait
SQL> -- events (event column). You can research and find out what the wait
SQL> -- event indicates (along with its parameters) by checking the Oracle
SQL> -- Server Reference Manual or look for any known issues or documentation
SQL> -- by searching Metalink for the event name in the search bar. Example
SQL> -- (include single quotes): [ 'buffer busy due to global cache' ].
SQL> -- Metalink and/or the Server Reference Manual should return some useful
SQL> -- information on each type of wait event. The inst_id column shows the
SQL> -- instance where the session resides and the SID is the unique identifier
SQL> -- for the session (gv$session). The p1, p2, and p3 columns will show
SQL> -- event specific information that may be important to debug the problem.
SQL> -- To find out what the p1, p2, and p3 indicates see the next section.
SQL> -- Items with wait_time of anything other than 0 indicate we do not know
SQL> -- how long these sessions have been waiting.
SQL> -EM' sections if the
-- AVG GLOBAL LOCK GET TIME is high.
-set numwidth 20
column "AVG GLOBAL LOCK GET TIME (ms)" format 9999999.9
select b1.inst_id, (b1.value + b2.value) "GLOBAL LOCK GETS",
b3.value "GLOBAL LOCK GET TIME",
(b3.value / (b1.value + b2.value) a.sql active.sql active_rbs.sql active_temp.sq
l activep.sql activew.sql applied_logs.sql archivelog_histogram.sql asm_add_disk
_dg.sql asm_create_dg_ext_red.sql asm_dg_details.sql asm_dg_mon_rebal.sql asm_dg
_rebal_power.sql asm_drop_disk_dg.sql asm_used_space.sql blockers.sql buffer_map
.sql check_logs_applied.sql check_logs_recd.sql check_primary_stus.sql column_se
ttings.sql concat_sqltext.sql connect.sql connect_setup.sql cpu_usage.sql cr_inv
al.sql create_cdrs_user.sql create_indexes_restore.sql create_indexes_restore2.s
ql create_scripts.ksh create_user_ERIC_RESTORE.sql defcall.sql delete_old_disk_b
ackups.sql desc.sql dict_temp_usage.sql dyn_alter_temp_tspace.sql dyn_alter_user
_cashown.sql epoc.sql explain2.sql explain3.sql file_ts.sql free_used_blocks.sql
freeblock.sql freeblocks.sql freeblocksts.sql freespce.sql freespce734.sql free
spce_pre8 get_extents.sql get_part.sql get_set_newnames.sql get_sql.sql get_sqlt
ext.sql glogin.sql how_to_start_auto_recovery.sql indcol.sql lib_locks.sql local
_temp_usage.sql lockers.sql locks.sql locks2.sql long_runners.sql long_running_j
obs.sql longops.sql minshpool.sql mon_locks.sql mon_rec_proc.sql mon_rec_process
.sql monitor_temp_space.sql next_extent_fail.sql next_extent_fail_max.sql next_e

xtent_fail_size.sql open_cursor_count.sql output.sql priv_users.sql proc_syntax.


sql proc_triggers.sql rac_diag.sql ray_sql.tar useful_scripts.log useful_scripts
.tar useful_scripts2.log useful_scripts3.log 10) "AVG GLOBAL LOCK GET TIME (ms)"
from gv$sysstat b1, gv$sysstat b2, gv$sysstat b3
where b1.name = 'global lock sync gets' and
b2.name = 'global lock async gets' and b3.name = 'global lock get time'
and b1.inrac_
SET ECHO OFF
REM
REM Check for available free space
REM
@save_sqlplus_settings
set linesize 150
set pages 100
set feedback off
set verify off
column db_block_size new_value blocksize noprint
SELECT value db_block_size
FROM v$parameter
WHERE name='db_block_size';
col db_name new_value db_name noprint
select replace(global_name,'.WORLD','') db_name
from global_name
/
col timestamp new_value timestamp noprint
select TO_CHAR(sysdate,'yyyymmddhh24miss') timestamp
from Dual
/
# define DBU_LOG=c:rayfreespace_logs
define DBU_LOG=$HOME/log
TTITLE CENTER 'Tablespace free space' SKIP 1
COLUMN tsname FORMAT a25
COLUMN allocation_type FORMAT A4 TRU HEADING "ALLO|TYPE"
COLUMN extent_management FORMAT A6 TRU HEADING "EXTNT|MNGMNT"
COLUMN contents FORMAT A4 TRU HEADING "CONTENTS"
COLUMN Tot_Size FORMAT 999,999,999 HEADING "ALLOCATED(M)"
COLUMN Tot_Free FORMAT 999,999 HEADING "FREE(M)"
COLUMN Tot_Used FORMAT 999,999,999 HEADING "USED(M)"
-- COLUMN Pct_Used FORMAT 999 HEADING "USED %"
COLUMN Pct_Used FORMAT A6 HEADING "USED %"
COLUMN Fragments FORMAT 99,999 HEADING "FRAGMTS"
COLUMN Large_Ext FORMAT 999,999 HEADING "LARG(M)"
COLUMN IncrmntBytes FORMAT 999,999 HEADING "AUTOEXTEND|MAX ALLOWED|BYTES(M)"
COLUMN Pct_Temp_Actual_Used FORMAT a7 HEAD "PCT|TEMP|ACT|USED"
break on report
compute Sum LABEL SUM of Tot_Size on report
compute Sum LABEL SUM of Tot_free on report
compute Sum LABEL SUM of Tot_Used on report
set feedback off pages 999 trims on
spool &DBU_LOG/freespce_&db_name._&timestamp..log
SELECT a.tablespace_name TSNAME,
DECODE(Sort_Usage.Percent_Used,NULL,ROUND(SUM(a.tots)/1048576,0),(sort_usage.tot
_avail_blocks*dt.block_size)/1048576) Tot_Size,
DECODE(Sort_Usage.Percent_Used,NULL,ROUND((SUM(a.tots)/1048576)-nvl((SUM(a.sumb)
/1048576),0),0),(sort_usage.tot_used_blocks*dt.block_size)/1048576) Tot_Used,
DECODE(Sort_Usage.Percent_Used,NULL,ROUND(SUM(a.sumb)/1048576,0),(sort_usage.tot
_free_blocks*dt.block_size)/1048576) Tot_Free,

-- DECODE(Sort_Usage.Percent_Used,NULL,LPAD(ROUND(((SUM(a.tots)-SUM(a.sumb))/sum
(a.tots))*100,0)||'%',6,CHR(32)),Sort_Usage.Percent_Used||'%') Pct_Used,
DECODE(Sort_Usage.Percent_Used,NULL,LPAD(ROUND(((SUM(a.tots)-SUM(a.sumb))/sum(a.
tots))*100,0)||'%',6,CHR(32)),
LPAD(Sort_Usage.Percent_Used||'%',6,CHR(32))) Pct_Used,
ROUND(SUM(a.largest)/1048576,0) Large_Ext,
SUM(a.chunks) Fragments,
b.contents, b.allocation_type,
b.extent_management,
DECODE(SUM(a.IncrmntBytes),0,0, ROUND(SUM(a.tots)/1048576,0)+round(sum(a.Incrmnt
Bytes/1024/1024),0)) IncrmntBytes
FROM dba_tablespaces dt,
(SELECt tablespace_name, 0 tots, SUM(bytes) sumb,
MAX(bytes) largest, COUNT(*) chunks,0 IncrmntBytes
FROM dba_free_space a
GROUP BY tablespace_name
UNION
SELECT tablespace_name, SUM(bytes) tots, 0, 0, 0, SUM(DECODE(maxbytes,0,0,maxbyt
es-bytes))
FROM dba_data_files f
GROUP BY tablespace_name
UNION
SELECT tablespace_name, SUM(bytes) tots, 0, 0, 0,0
FROM dba_temp_files
GROUP BY tablespace_name) a, dba_tablespaces b,
(
SELECT f.tablespace_name,
DECODE(s.tot_used_blocks,NULL,0,ROUND((s.tot_used_blocks/f.total_blocks)*100,0))
percent_used,
s.tot_avail_blocks,
s.tot_free_blocks,
s.tot_used_blocks
FROM
(
SELECT tablespace_name,
SUM(total_blocks) tot_avail_blocks,
SUM(free_blocks) tot_free_blocks,
SUM(used_blocks) tot_used_blocks
FROM gv$sort_segment
GROUP BY tablespace_name
) s,
(
SELECT tablespace_name, sum(blocks) total_blocks
FROM dba_temp_files
GROUP BY tablespace_name
) f
WHERE f.tablespace_name = s.tablespace_name(+)) SORT_USAGE
WHERE b.tablespace_name = a.tablespace_name
AND b.tablespace_name = dt.tablespace_name
AND b.TABLESPACE_NAME LIKE UPPER('&Tspace'||'%')
AND b.Tablespace_Name = Sort_Usage.Tablespace_name(+)
GROUP BY a.tablespace_name,
Sort_Usage.Percent_Used,
sort_usage.tot_avail_blocks,
dt.block_size,
sort_usage.tot_used_blocks,
sort_usage.tot_free_blocks,
b.contents,
b.allocation_type,
b.extent_management

ORDER BY 1
/
spool off
set linesize 80
@sqlplus_settings
set term on
ttitle off
PROMPT
prompt
prompt Output saved at &DBU_LOG/freespce_&db_name._&timestamp..log
PROMPT
PROMPT
COLUMN PCT_USED DEFAULT
UNDEFINE TSPACE
SET ECHO ON
######################
[LNDBDD2]oracle@dbdatad1 $ cat dbcheck.sql
rem# One Stop Database Sanity Check Script
rem
break on today
column today noprint new_value xdate
select substr(to_char(sysdate,'fmMonth DD, YYYY HH:MI:SS P.M.'),1,35) today from
dual;
column name noprint new_value dbname
select name from v$database;
set heading on
set feedback off
spool dbcheck.lst
prompt
prompt
prompt
ttitle
select
prompt
prompt
ttitle

**********************************************************
*****
Database Information
*****
**********************************************************
left "DATABASE: "dbname"
(AS OF: "xdate")"
name, created, log_mode from v$database;
**********************************************************
off

rem ------------------------------------------------------------rem
DB Block Buffer - Hit Ratio
rem ------------------------------------------------------------clear breaks
clear computes
set heading off
set feedback off
set termout off
create
PR
CG
dbbg

table dbbb (
number,
number,
number);

insert into DBBB values (0,0,0);


UPDATE dbbb
set dbbg =
(SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'db block gets');
UPDATE dbbb
set cg =
(SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'consistent gets');
UPDATE dbbb
set pr =
(SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'physical reads');
set heading on
set termout on
column
column
column
column

"Physical Reads" format 99,999,999,999


"Consistent Gets" format 99,999,999,999
"DB Block Gets" format 99,999,999,999
"Percent (Above 70% ?)" format 999.99

TTitle left "***** Database: "dbname", DB Block Buffers ( As of: "xdate" )


*****"
skip 1 - left "Percent = (100*(1-(Physical Reads/(Consistent Gets + DB Block Ge
ts))))" skip 2
SELECT pr "Physical Reads",
cg "Consistent Gets",
dbbg "DB Block Gets",
(100*(1-(PR/(CG+dbbg)))) "Percent (Above 70% ?)"
from dbbb;
set heading off
set termout off
drop table dbbb;
ttitle off
clear breaks
clear computes
set heading on
set termout on
rem ------------------------------------------------------------rem
Shared Pool Size - Gets and Misses
rem ------------------------------------------------------------set line 150
column
column
column
column

"Executions" format 999,999,990


"Cache Misses Executing" format 999,999,990
"Data Dictionary Gets" format 999,999,999
"Get Misses" format 999,999,999

ttitle left skip 1 - left "**********


**********" skip 1

Shared Pool Size (Execution Misses)

select sum(pins) "Executions",


sum(reloads) "Cache Misses Executing",
(sum(reloads)/sum(pins)*100) "% Ratio (STAY UNDER 1%)"
from v$librarycache;
ttitle left "**********
skip 1

Shared Pool Size (Dictionary Gets)

**********"

select sum(gets) "Data Dictionary Gets",


sum(getmisses) "Get Misses",
100*(sum(getmisses)/sum(gets)) "% Ratio (STAY UNDER 12%)"
from v$rowcache;
ttitle off
rem ------------------------------------------------------------rem
Log Buffer
rem ------------------------------------------------------------ttitle left "**********

Log Buffers

**********" skip 1

select substr(name,1,25) Name,


substr(value,1,15) "VALUE (Near 0?)"
from v$sysstat
where name = 'redo log space requests';
ttitle off
rem ------------------------------------------------------------rem
Latch Contention
rem ------------------------------------------------------------ttitle left "**********

Latch Information

**********" skip 1

select substr(l.name,1,25) Name,


l.gets, l.misses,
l.immediate_gets, l.immediate_misses
from v$latch l, v$latchname ln
where ln.name in ('redo allocation', 'redo copy')
and ln.latch# = l.latch#;
ttitle off
rem ------------------------------------------------------------rem
Reinstates the xdbname parameter
rem ------------------------------------------------------------column name noprint new_value xdbname
select name from v$database;
rem ------------------------------------------------------------rem
Tablespace Usage
rem ------------------------------------------------------------set pagesize 66
set line 132
clear breaks
clear computes
column
column
column
column

"Total Bytes" format 9,999,999,999


"SQL Blocks" format 999,999,999
"VMS Blocks" format 999,999,999
"Bytes Free" format 9,999,999,999

column "Bytes Used" format 9,999,999,999


column "% Free" format 9999.999
column "% Used" format 9999.999
break on report
compute sum of "Total Bytes" on report
compute sum of "SQL Blocks" on report
compute sum of "VMS Blocks" on report
compute sum of "Bytes Free" on report
compute sum of "Bytes Used" on report
compute avg of "% Free" on report
compute avg of "% Used" on report
TTitle left "******* Database: "dbname", Current Tablespace Usage ( As of:
"xdate" ) *******" skip 1
select substr(fs.FILE_ID,1,3) "ID#",
fs.tablespace_name,
df.bytes "Total Bytes",
df.blocks "SQL Blocks",
df.bytes/512 "VMS Blocks",
sum(fs.bytes) "Bytes Free",
(100*((sum(fs.bytes))/df.bytes)) "% Free",
df.bytes-sum(fs.bytes) "Bytes Used",
(100*((df.bytes-sum(fs.bytes))/df.bytes)) "% Used"
from sys.dba_data_files df, sys.dba_free_space fs
where df.file_id(+) = fs.file_id
group by fs.FILE_ID, fs.tablespace_name, df.bytes, df.blocks
order by fs.tablespace_name;
ttitle off
rem ------------------------------------------------------------rem
Disk Activity
rem ------------------------------------------------------------column "File Total" format 99,999,990
set line 132
set pagesize 33
ttitle "
xdate " )

*****
*****"

Database: "dbname", DataFile's Disk Activity (As of:"

select substr(df.file#,1,2) "ID",


rpad(substr(name,1,52),52,'.') "File Name",
rpad(substr(phyrds,1,10),10,'.') "Phy Reads",
rpad(substr(phywrts,1,10),10,'.') "Phy Writes",
rpad(substr(phyblkrd,1,10),10,'.') "Blk Reads",
rpad(substr(phyblkwrt,1,10),10,'.') "Blk Writes",
rpad(substr(readtim,1,9),9,'.') "Read Time",
rpad(substr(writetim,1,10),10,'.') "Write Time",
(sum(phyrds+phywrts+phyblkrd+phyblkwrt+readtim)) "File Total"
from v$filestat fs, v$datafile df
where fs.file# = df.file#
group by df.file#, df.name, phyrds, phywrts, phyblkrd,
phyblkwrt, readtim, writetim
order by sum(phyrds+phywrts+phyblkrd+phyblkwrt+readtim) desc, df.name;
ttitle off

rem ------------------------------------------------------------rem
Fragmentation Need
rem ------------------------------------------------------------set
set
set
set

heading on
termout on
pagesize 66
line 132

ttitle left "


*****
" xdate "
*****"

Database: "dbname", DEFRAGMENTATION NEED, AS OF:

select substr(de.owner,1,8) "Owner",


substr(de.segment_type,1,8) "Seg Type",
substr(de.segment_name,1,35) "Table Name (Segment)",
substr(de.tablespace_name,1,20) "Tablespace Name",
count(*) "Frag NEED",
substr(df.name,1,40) "DataFile Name"
from sys.dba_extents de, v$datafile df
where de.owner <> 'SYS'
and de.file_id = df.file#
and de.segment_type = 'TABLE'
group by de.owner, de.segment_name, de.segment_type, de.tablespace_name,
df.name
having count(*) > 1
order by count(*) desc;
ttitle off
rem ------------------------------------------------------------rem
Rollback Information
rem ------------------------------------------------------------set pagesize 66
set line 132
TTitle left "*** Database: "dbname", Rollback Information ( As of: " xdate "
) ***" skip 2
select substr(sys.dba_rollback_segs.SEGMENT_ID,1,5) "ID#",
substr(sys.dba_segments.OWNER,1,8) "Owner",
substr(sys.dba_segments.TABLESPACE_NAME,1,17) "Tablespace Name",
substr(sys.dba_segments.SEGMENT_NAME,1,17) "Rollback Name",
substr(sys.dba_rollback_segs.INITIAL_EXTENT,1,10) "INI_Extent",
substr(sys.dba_rollback_segs.NEXT_EXTENT,1,10) "Next Exts",
substr(sys.dba_segments.MIN_EXTENTS,1,5) "MinEx",
substr(sys.dba_segments.MAX_EXTENTS,1,5) "MaxEx",
substr(sys.dba_segments.PCT_INCREASE,1,5) "%Incr",
substr(sys.dba_segments.BYTES,1,15) "Size (Bytes)",
substr(sys.dba_segments.EXTENTS,1,6) "Extent#",
substr(sys.dba_rollback_segs.STATUS,1,10) "Status"
from sys.dba_segments, sys.dba_rollback_segs
where sys.dba_segments.segment_name = sys.dba_rollback_segs.segment_name and
sys.dba_segments.segment_type = 'ROLLBACK'
order by sys.dba_rollback_segs.segment_id;
ttitle off

TTitle left " " skip 2 - left "*** Database: "dbname", Rollback Status ( As of:
" xdate " ) ***" skip 2
select substr(V$rollname.NAME,1,20) "Rollback_Name",
substr(V$rollstat.EXTENTS,1,6) "EXTENT",
v$rollstat.RSSIZE, v$rollstat.WRITES,
substr(v$rollstat.XACTS,1,6) "XACTS",
v$rollstat.GETS,
substr(v$rollstat.WAITS,1,6) "WAITS",
v$rollstat.HWMSIZE, v$rollstat.SHRINKS,
substr(v$rollstat.WRAPS,1,6) "WRAPS",
substr(v$rollstat.EXTENDS,1,6) "EXTEND",
v$rollstat.AVESHRINK,
v$rollstat.AVEACTIVE
from v$rollname, v$rollstat
where v$rollname.USN = v$rollstat.USN
order by v$rollname.USN;
ttitle off
TTitle left " " skip 2 - left "*** Database: "dbname", Rollback Segment Mapping
( As of: " xdate " ) ***" skip 2
select r.name Rollback_Name,
p.pid Oracle_PID,
p.spid VMS_PID,
nvl(p.username,'NO TRANSACTION') Transaction,
p.terminal Terminal
from v$lock l, v$process p, v$rollname r
where l.addr = p.addr(+)
and trunc(l.id1(+)/65536)=r.usn
and l.type(+) = 'TX'
and l.lmode(+) = 6
order by r.name;
ttitle off
rem ------------------------------------------------------------rem
Current Users
rem ------------------------------------------------------------set line 132
set pagesize 66
TTitle left "***
**" skip 1

Database: "dbname", Current User Info (As of: "xdate")

select substr(s.username,1,15) "DB UserName",


s.osuser "OS UserName",
substr(a.object,1,25) Object,
a.type , s.command,
substr(s.machine,1,15) Machine,
substr(s.terminal,1,15) Terminal, s.process, s.status
from v$access a, v$session s
where a.sid = s.sid
order by username;
TTitle left "***
*" skip 1

Database: "dbname", Current Sessions (As of: "xdate")

**

select substr(username,1,15) "DB UserName",


substr(osuser,1,15) "OS UserName",
substr(command,1,3) CMD,
substr(machine,1,10) Machine,
terminal, process, status,
substr(program,1,50) "OS Program Name"
from v$session
where type = 'USER'
order by username;
TTitle left "***
ip 1

Database: "dbname", Current Access (As of: "xdate") ***" sk

select sid,
substr(owner,1,15) Owner,
substr(object,1,25) Object,
type
from v$access
order by owner;
rem ------------------------------------------------------------rem ------------------------------------------------------------spool off
set feedback on
exit
[LNDBDD2]oracle@dbdatad1 $

#############
SQL> !cat locked_objects.sql
set lines 500
col owner form a10
col object_name form a40
select a.owner,a.object_name,a.object_type,b.SESSION_ID,b.ORACLE_USERNAME,b.OS_U
SER_NAME
from dba_objects a,V$LOCKED_OBJECT b
where a.OBJECT_ID = b.OBJECT_ID
/

##########
[LNP2B2U2]oracle@crm2u2 $ cat shrink_anal.sql
set linesize 200
set pagesize 200
col
col
col
col

"Tablespace"
"Segment Name"
"Datafile Location"
"Highwater Mark (Mb)"

format a20
format a45 heading "Segment|Name"
format a50 heading "Datafile|Location"
heading "Highwater|Mark (Mb)"

select ddf.tablespace_name "Tablespace", ddf.file_name "Datafile Location", ddf.


bytes/(1024*1024) "Size (Mb)",
round(((hwm.maximum+de.blocks-1)*dbs.db_block_size)/(1024*1024),2) "Highw
ater Mark (Mb)",
de.owner||'.'||de.segment_name "Segment Name", de.segment_type "Type"
from dba_data_files ddf, (select file_id, max(block_id) maximum
from dba_extents
group by file_id) hwm,
dba_extents de, (select value db_block_size
from v$parameter
where name='db_block_size') dbs
where ddf.file_id = hwm.file_id
and de.file_id = hwm.file_id
and de.block_id = hwm.maximum
order by 1, 2, 6, 5 ;
###############
[LNP2B2U2]oracle@crm2u2 $ cat dbms_space_trend.sql
set echo off
@@save_sqlplus_settings
COLUMN timepoint FORMAT A30
SELECT *
FROM TABLE(DBMS_SPACE.object_growth_trend ('AUD_OWNER','AUD_COPY','TABLE'))
ORDER BY timepoint;
@@sqlplus_settings
set echo on
#############

[LNP2B2U2]oracle@crm2u2 $ cat param_changes.sql


set echo off
@@save_sqlplus_settings
-- parm_mods.sql
--- Shows all parameters (including hidden) that have been modified.
-- Uses the lag function so that a single record is returned for each change.
-- It uses AWR data - so only snapshots still in the database will be included.
--- The script prompts for a parameter name (which can be wild carded).
-- Leaving the parameter name blank matches any parameter (i.e. it will show all
changes).
-- Calculated hidden parameters (those that start with two underscores like "__s
hared_pool_size")
-- will not be displayed unless requested with a Y.
--- Kerry Osborne
--- Note: I got this idea from Jeff White.
-set linesize 155
col time for a15
col parameter_name format a50
col old_value format a30

col new_value format a30


break on instance skip 3
select instance_number instance, snap_id, time, parameter_name, old_value, new_v
alue from (
select a.snap_id,to_char(end_interval_time,'DD-MON-YY HH24:MI') TIME, a.instance
_number, parameter_name, value new_value,
lag(parameter_name,1) over (partition by parameter_name, a.instance_number order
by a.snap_id) old_pname,
lag(value,1) over (partition by parameter_name, a.instance_number order by a.sna
p_id) old_value ,
decode(substr(parameter_name,1,2),'__',2,1) calc_flag
from dba_hist_parameter a, dba_Hist_snapshot b , v$instance v
where a.snap_id=b.snap_id
and a.instance_number=b.instance_number
and parameter_name like nvl('&parameter_name',parameter_name)
and a.instance_number like nvl('&instance_number',v.instance_number)
)
where
new_value != old_value
and calc_flag not in (decode('&show_calculated','Y',3,2))
order by 1,2
/
@sqlplus_settings
set echo on

#################
[LNP2B2U2]oracle@crm2u2 $ cat audcheck_excl10g.sql
set echo off
@@save_sqlplus_settings.sql
set lines 142
set verify off
ACCEPT USERID
CHAR PROMPT "Enter UserId ==============================
========> " default '%'
ACCEPT USERID_LEN2
NUMBER PROMPT "Enter length of Userid ==================
========> " default 0
ACCEPT TIMESTAMP_S
CHAR PROMPT "Enter Timestamp start [DD-MON-YYYY HH24:MI:
SS] ===> " default '01-JAN-2001 00:00:00'
ACCEPT TIMESTAMP_E
CHAR PROMPT "Enter Timestamp end
[DD-MON-YYYY HH24:MI
:SS] ===> " default '01-JAN-2020 00:00:00'
ACCEPT ACTION
CHAR PROMPT "Enter Action ==============================
========> " default '%'
col USERID_LEN3 new_value USERID_LEN3 noprint
SELECT GREATEST(LENGTH(DECODE('&USERID','%',LPAD('0',30,'0'),'&USERID')),&USERI
D_LEN2) USERID_LEN3
FROM
Dual;
col
col
col
col

OSUSER_LEN new_value OSUSER_LEN noprint


HOSTTERM_LEN new_value HOSTTERM_LEN noprint
NAME_LEN new_value NAME_LEN noprint
USERID_LEN new_value USERID_LEN noprint

SELECT 'A'||MAX(col_length.OSUSER_LEN) OSUSER_LEN,


'A'||MAX(col_length.hostterm_LEN) hostterm_LEN,
'A'||MAX(col_length.NAME_LEN) NAME_LEN,

'A'||MAX(col_length.USERID_LEN) USERID_LEN
FROM
(
SELECT MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE WHEN ac.action in (100,101,102)
THEN
MAX(LENGTH(TRIM(aa.name)))
ELSE
MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$G
RANTEE))
END
NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
GROUP BY ac.action
UNION
SELECT 8 OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
MAX(LENGTH(TRIM(aa.name))) NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
UNION
SELECT MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE WHEN ac.action# in (100,101,102)
THEN
MAX(LENGTH(TRIM(aa.name)))
ELSE
MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$G
RANTEE))
END
NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
sys.aud$
ac,
audit_actions aa

WHERE aa.action
=
ac.action#
AND
userid like UPPER('&Userid.%')
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
GROUP BY ac.action#
) col_length
/
col OSUSER
format &OSUSER_Len
Head "OSUSER"
col HOSTTERM
format &HOSTTERM_Len
Head "HOST:TERM"
#col NAME
format &NAME_Len
Head "ACTION"
col USERID format &USERID_LEN HEAD "USERID"
col timestamp format a20
col returncode format 99999 HEAD "RETRN|CODE"
alter session set nls_date_format='DD_MON-YYYY HH24:MI:SS';
SELECT userid,
TO_CHAR(timestamp,'DD-MON-YYYY HH24:MI:SS') timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
CASE WHEN ac.action in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END
NAME,
returncode,
spare1 osuser,
logoff$time
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
UNION
SELECT userid,
TO_CHAR(timestamp,'DD-MON-YYYY HH24:MI:SS'),
TRIM(userhost)||':'||TRIM(terminal) hostterm,
aa.name name,
returncode,

'UNKNOWN' osuser,
logoff$time
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
UNION
SELECT userid,
TO_CHAR(ntimestamp#,'DD-MON-YYYY HH24:MI:SS'),
TRIM(userhost)||':'||TRIM(terminal) hostterm,
CASE WHEN ac.action# in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END
NAME,
returncode,
spare1 osuser,
logoff$time
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
ORDER BY 2
/

###########
[LNP2B2U2]oracle@crm2u2 $ cat audcheck11g.sql
set echo off
/*===================================================================
||
|| Filename:
audcheck11g.sql
||
|| Views:

||
aud_owner,aud_copy
||
audit_actions
||
aud_owner.aud_logins
||
sys.aud$
||
|| Details:
||
|| 19/12/2010 Ray Metz
Created
|| 21/12/2011 Ray Metz
Improved output to show non-login
||
information i.e. GRANT, REVOKE
===================================================================*/
@@save_sqlplus_settings.sql
set lines 220
set verify off
ACCEPT USERID
CHAR PROMPT "Enter UserId ==============================
========> " default '%'
ACCEPT USERID_LEN2
NUMBER PROMPT "Enter length of Userid ==================
========> " default 0
ACCEPT TIMESTAMP_S
CHAR PROMPT "Enter Timestamp start [DD-MON-YYYY HH24:MI:
SS] ===> " default '01-JAN-2001 00:00:00'
ACCEPT TIMESTAMP_E
CHAR PROMPT "Enter Timestamp end
[DD-MON-YYYY HH24:MI
:SS] ===> " default '01-JAN-2020 00:00:00'
ACCEPT ACTION
CHAR PROMPT "Enter Action ==============================
========> " default '%'
col USERID_LEN3 new_value USERID_LEN3 noprint
SELECT GREATEST(LENGTH(DECODE('&USERID','%',LPAD('0',30,'0'),'&USERID')),&USERI
D_LEN2) USERID_LEN3
FROM
Dual;
col
col
col
col

OSUSER_LEN new_value OSUSER_LEN noprint


HOSTTERM_LEN new_value HOSTTERM_LEN noprint
NAME_LEN new_value NAME_LEN noprint
USERID_LEN new_value USERID_LEN noprint

SELECT MAX(col_length.OSUSER_LEN) OSUSER_LEN,


MAX(col_length.hostterm_LEN) hostterm_LEN,
MAX(col_length.NAME_LEN) NAME_LEN,
MAX(col_length.USERID_LEN) USERID_LEN
FROM
(
SELECT 'A'||MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
'A'||MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE
WHEN
ac.action in (100,101,102)
THEN
'A'||MAX(LENGTH(aa.name))
ELSE
'A'||MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||A
UTH$GRANTEE))
END NAME_LEN ,
'A'||MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
GROUP BY ac.action

UNION
SELECT 'A8' OSUSER_LEN,
'A'||MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
'A'||MAX(LENGTH(TRIM(aa.name))) NAME_LEN,
'A'||MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT 'A'||MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
'A'||MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE
WHEN
ac.action# in (100,101,102)
THEN
'A'||MAX(LENGTH(aa.name))
ELSE
'A'||MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||A
UTH$GRANTEE))
END NAME_LEN ,
'A'||MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
userid like UPPER('&Userid.%')
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
GROUP BY ac.action#
) col_length
/
col
col
col
col
col

OSUSER
format &OSUSER_Len
Head "OSUSER"
HOSTTERM
format &HOSTTERM_Len
Head "HOST:TERM"
NAME
format &NAME_Len
Head "ACTION"
USERID format &USERID_LEN HEAD "USERID"
timestamp format a30

alter session set nls_date_format='DD_MON-YYYY HH24:MI:SS';


SELECT userid,
timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
returncode,
spare1 osuser,
logoff$time,
CASE
WHEN
ac.action in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END name
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action

AND
AND
AND
AND
AND
UNION
SELECT

FROM

(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )


timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
aa.name
LIKE
UPPER('&ACTION.%')
LENGTH(userid) <=
&USERID_LEN3
userid,
timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
returncode,
'UNKNOWN' osuser,
logoff$time,
aa.name name
aud_owner.aud_logins ac,
audit_actions aa
aa.action
=
ac.action
userid like UPPER('&Userid.%')
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
aa.name
LIKE
UPPER('&ACTION.%')
LENGTH(userid) <=
&USERID_LEN3

WHERE
AND
AND
AND
AND
AND
UNION
SELECT userid,
ntimestamp#,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
returncode,
spare1 osuser,
logoff$time,
CASE
WHEN
ac.action# in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END name
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
ORDER BY 2
/
@@sqlplus_settings.sql
set echo on

############
[LNP2B2U2]oracle@crm2u2 $ cat audcheck9i.sql
set echo off
/*===================================================================
||
|| Filename:
audcheck9i.sql
||
|| Views:
||

|| Details:
||
|| 19/12/10
Ray Metz
Created
||
===================================================================*/
set echo off
@@save_sqlplus_settings.sql
set lines 132
set verify off
ACCEPT USERID
CHAR PROMPT "Enter UserId ==============================
========> " default '%'
ACCEPT USERID_LEN2
NUMBER PROMPT "Enter length of Userid ==================
========> " default 0
ACCEPT TIMESTAMP_S
CHAR PROMPT "Enter Timestamp start [DD-MON-YYYY HH24:MI:
SS] ===> " default '01-JAN-2001 00:00:00'
ACCEPT TIMESTAMP_E
CHAR PROMPT "Enter Timestamp end
[DD-MON-YYYY HH24:MI
:SS] ===> " default '01-JAN-2020 00:00:00'
ACCEPT ACTION
CHAR PROMPT "Enter Action ==============================
========> " default '%'
col USERID_LEN3 new_value USERID_LEN3 noprint
SELECT GREATEST(LENGTH(DECODE('&USERID','%',LPAD('0',30,'0'),'&USERID')),&USERI
D_LEN2) USERID_LEN3
FROM
Dual;
col
col
col
col

OSUSER_LEN new_value OSUSER_LEN noprint


HOSTTERM_LEN new_value HOSTTERM_LEN noprint
NAME_LEN new_value NAME_LEN noprint
USERID_LEN new_value USERID_LEN noprint

SELECT 'A'||MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,


'A'||MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
'A'||MAX(LENGTH(TRIM(DECODE(aa.name,'DROP USER','DROP USER '||obj$name,'
ALTER USER','ALTER USER '||obj$name,aa.name)))) NAME_LEN,
'A'||MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT 'A8' OSUSER_LEN,
'A'||MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
'A'||MAX(LENGTH(TRIM(aa.name))) NAME_LEN,
'A'||MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT 'A'||MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
'A'||MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
'A'||MAX(LENGTH(TRIM(DECODE(aa.name,'DROP USER','DROP USER '||obj$name,'

ALTER USER','ALTER USER '||obj$name,aa.name)))) NAME_LEN,


'A'||MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
userid like UPPER('&Userid.%')
AND
timestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
/
col
col
col
col
col

OSUSER
format &OSUSER_Len
Head "OSUSER"
HOSTTERM
format &HOSTTERM_Len
Head "HOST:TERM"
NAME
format &NAME_Len
Head "ACTION"
USERID format &USERID_LEN HEAD "USERID"
timestamp format a30

alter session set nls_date_format='DD_MON-YYYY HH24:MI:SS';


SELECT userid,
timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
DECODE(aa.name,'DROP USER','DROP USER '||obj$name,'ALTER USER','ALTER US
ER '||obj$name,aa.name) name,
returncode,
spare1 osuser,
logoff$time
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT userid,
timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
aa.name name,
returncode,
'UNKNOWN' osuser,
logoff$time
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT userid,
timestamp#,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
DECODE(aa.name,'DROP USER','DROP USER '||obj$name,'ALTER USER','ALTER US
ER '||obj$name,aa.name) name,
returncode,

spare1 osuser,
logoff$time
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
timestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
ORDER BY 2
/
@@sqlplus_settings.sql
set echo on
############

[LNP2B2U2]oracle@crm2u2 $ cat audcheck10g.sql


set echo off
@@save_sqlplus_settings.sql
set lines 142
set verify off
ACCEPT USERID
CHAR PROMPT "Enter UserId ==============================
========> " default '%'
ACCEPT USERID_LEN2
NUMBER PROMPT "Enter length of Userid ==================
========> " default 0
ACCEPT TIMESTAMP_S
CHAR PROMPT "Enter Timestamp start [DD-MON-YYYY HH24:MI:
SS] ===> " default '01-JAN-2001 00:00:00'
ACCEPT TIMESTAMP_E
CHAR PROMPT "Enter Timestamp end
[DD-MON-YYYY HH24:MI
:SS] ===> " default '01-JAN-2020 00:00:00'
ACCEPT ACTION
CHAR PROMPT "Enter Action ==============================
========> " default '%'
col USERID_LEN3 new_value USERID_LEN3 noprint
SELECT GREATEST(LENGTH(DECODE('&USERID','%',LPAD('0',30,'0'),'&USERID')),&USERI
D_LEN2) USERID_LEN3
FROM
Dual;
col
col
col
col

OSUSER_LEN new_value OSUSER_LEN noprint


HOSTTERM_LEN new_value HOSTTERM_LEN noprint
NAME_LEN new_value NAME_LEN noprint
USERID_LEN new_value USERID_LEN noprint

SELECT 'A'||MAX(col_length.OSUSER_LEN) OSUSER_LEN,


'A'||MAX(col_length.hostterm_LEN) hostterm_LEN,
'A'||MAX(col_length.NAME_LEN) NAME_LEN,
'A'||MAX(col_length.USERID_LEN) USERID_LEN
FROM
(
SELECT MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE WHEN ac.action in (100,101,102)
THEN
MAX(LENGTH(TRIM(aa.name)))
ELSE
MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$G
RANTEE))
END
NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN

FROM

aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
GROUP BY ac.action
UNION
SELECT 8 OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
MAX(LENGTH(TRIM(aa.name))) NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE WHEN ac.action# in (100,101,102)
THEN
MAX(LENGTH(TRIM(aa.name)))
ELSE
MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$G
RANTEE))
END
NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
userid like UPPER('&Userid.%')
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
GROUP BY ac.action#
) col_length
/
col OSUSER
format &OSUSER_Len
Head "OSUSER"
col HOSTTERM
format &HOSTTERM_Len
Head "HOST:TERM"
#col NAME
format &NAME_Len
Head "ACTION"
col USERID format &USERID_LEN HEAD "USERID"
col timestamp format a20
col returncode format 99999 HEAD "RETRN|CODE"
alter session set nls_date_format='DD_MON-YYYY HH24:MI:SS';
SELECT userid,
TO_CHAR(timestamp,'DD-MON-YYYY HH24:MI:SS') timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
CASE WHEN ac.action in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END
NAME,

FROM

returncode,
spare1 osuser,
logoff$time
aud_owner.aud_copy ac,
audit_actions aa
aa.action
=
ac.action
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
aa.name
LIKE
UPPER('&ACTION.%')
LENGTH(userid) <=
&USERID_LEN3

WHERE
AND
AND
AND
AND
AND
UNION
SELECT userid,
TO_CHAR(timestamp,'DD-MON-YYYY HH24:MI:SS'),
TRIM(userhost)||':'||TRIM(terminal) hostterm,
aa.name name,
returncode,
'UNKNOWN' osuser,
logoff$time
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
UNION
SELECT userid,
TO_CHAR(ntimestamp#,'DD-MON-YYYY HH24:MI:SS'),
TRIM(userhost)||':'||TRIM(terminal) hostterm,
CASE WHEN ac.action# in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END
NAME,
returncode,
spare1 osuser,
logoff$time
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
ORDER BY 2
/
@@sqlplus_settings.sql
set echo on

###############
[LNP2B2U2]oracle@crm2u2 $ cat audcheck_excl11g.sql
set echo off
/*===================================================================
||

|| Filename:
audcheck11g.sql
||
|| Views:
||
aud_owner,aud_copy
||
audit_actions
||
aud_owner.aud_logins
||
sys.aud$
||
|| Details:
||
|| 19/12/10
Ray Metz
Created
||
===================================================================*/
@@save_sqlplus_settings.sql
set lines 250
set verify off
ACCEPT USERID
CHAR PROMPT "Enter UserId ==============================
========> " default '%'
ACCEPT USERID_LEN2
NUMBER PROMPT "Enter length of Userid ==================
========> " default 0
ACCEPT TIMESTAMP_S
CHAR PROMPT "Enter Timestamp start [DD-MON-YYYY HH24:MI:
SS] ===> " default '01-JAN-2001 00:00:00'
ACCEPT TIMESTAMP_E
CHAR PROMPT "Enter Timestamp end
[DD-MON-YYYY HH24:MI
:SS] ===> " default '01-JAN-2020 00:00:00'
ACCEPT ACTION
CHAR PROMPT "Enter Action ==============================
========> " default '%'
col USERID_LEN3 new_value USERID_LEN3 noprint
SELECT GREATEST(LENGTH(DECODE('&USERID','%',LPAD('0',30,'0'),'&USERID')),&USERI
D_LEN2) USERID_LEN3
FROM
Dual;
col
col
col
col

OSUSER_LEN new_value OSUSER_LEN noprint


HOSTTERM_LEN new_value HOSTTERM_LEN noprint
NAME_LEN new_value NAME_LEN noprint
USERID_LEN new_value USERID_LEN noprint

SELECT 'A'||MAX(col_length.OSUSER_LEN) OSUSER_LEN,


'A'||MAX(col_length.hostterm_LEN) hostterm_LEN,
'A'||MAX(col_length.NAME_LEN) NAME_LEN,
'A'||MAX(col_length.USERID_LEN) USERID_LEN
FROM
(
SELECT MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE
WHEN
ac.action in (100,101,102)
THEN
MAX(LENGTH(aa.name))
ELSE
MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$G
RANTEE))
END NAME_LEN ,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')

AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
GROUP BY ac.action
UNION
SELECT 8 OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
MAX(LENGTH(TRIM(aa.name))) NAME_LEN,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
UNION
SELECT MAX(LENGTH(TRIM(spare1))) OSUSER_LEN,
MAX(LENGTH(TRIM(userhost)||':'||TRIM(terminal))) hostterm_LEN,
CASE
WHEN
ac.action# in (100,101,102)
THEN
MAX(LENGTH(aa.name))
ELSE
MAX(LENGTH(aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$G
RANTEE))
END NAME_LEN ,
MAX(LENGTH(TRIM(userid))) USERID_LEN
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
userid like UPPER('&Userid.%')
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
GROUP BY ac.action#
) col_length

/
col
col
col
col
col

OSUSER
format &OSUSER_Len
Head "OSUSER"
HOSTTERM
format &HOSTTERM_Len
Head "HOST:TERM"
NAME
format &NAME_Len
Head "ACTION"
USERID format &USERID_LEN HEAD "USERID"
timestamp format a30

alter session set nls_date_format='DD_MON-YYYY HH24:MI:SS';


spool audcheck.log
SELECT userid,
timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
returncode,
spare1 osuser,
logoff$time,
CASE
WHEN
ac.action in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END name
FROM
aud_owner.aud_copy ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
UNION
SELECT userid,
timestamp,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
returncode,
'UNKNOWN' osuser,
logoff$time,
aa.name name
FROM
aud_owner.aud_logins ac,
audit_actions aa
WHERE aa.action
=
ac.action
AND
userid like UPPER('&Userid.%')
AND
timestamp
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',

'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
UNION
SELECT userid,
ntimestamp#,
TRIM(userhost)||':'||TRIM(terminal) hostterm,
returncode,
spare1 osuser,
logoff$time,
CASE
WHEN
ac.action# in (100,101,102)
THEN
aa.name
ELSE
aa.name||' '||OBJ$CREATOR||' '||OBJ$NAME||' '||AUTH$GRANTEE
END name
FROM
sys.aud$
ac,
audit_actions aa
WHERE aa.action
=
ac.action#
AND
(userid like UPPER('&Userid.%') OR obj$name LIKE UPPER('&Userid.%') )
AND
ntimestamp#
between TO_DATE('&TIMESTAMP_S','DD-MON-YYYY HH24:MI:SS')
AND
TO_DATE('&TIMESTAMP_E','DD-MON-YYYY HH24:MI:SS')
AND
aa.name
LIKE
UPPER('&ACTION.%')
AND
LENGTH(userid) <=
&USERID_LEN3
AND
ac.userid
NOT IN ('ACCT_ADMIN','ACC_RELEASE','ANONYMOUS','AUDTASK'
,'AUD_OWNER','CM_PROD',
'CTXSRV','CTXSYS','DBA_MON','DBSNMP','DB_TOOLS','DIP','DMG','ESMDBA',
'EXFSYS','FOGLIGHT','HEALTH_CHECKS','HIDS_AUDITOR','MDDATA','MDSYS',
'OLAPSYS','OLAP_USER','OPS$ORACLE','ORACLE','ORDPLUGINS','ORDSYS',
'OUTLN','PERFSTAT','PUBLIC','QUEST_CENTRAL','SI_INFORMTN_SCHEMA','SYS',
'SYSMAN','SYSTEM','TRACESVR','TSMSYS','WEBSYS','WKSYS','WKUSER',
'WMSYS','XDB')
ORDER BY 2
/
spool off
@@sqlplus_settings.sql
set echo on

#############
[LNP2B2U2]oracle@crm2u2 $ cat tabdep.sql
set echo off
/*===================================================================
||
|| Filename:
tabdep.sql
||
|| Views:
||
dba_tab_columns
||
dba_constraints
||
dba_cons_columns
||
dba_indexes
||
dba_ind_columns
||
dba_indexes
||
dba_constraints
||
dba_constraints

||
dba_constraints
||
dba_constraints
||
dba_constraints
||
dba_constraints
||
dba_dependencies
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
||
===================================================================*/
--- By Brian Peasland
-- 13 August 1999
--- This script is useful when a table needs to be dropped for some reason.
-- This script will show the table structure, any indexes on the table,
-- any constraints on the table, any foreign key references to other tables,
-- and any foreign key references to this table.
-- By using this script, one can drop a table and recreate it with the
-- exact setup. This is useful when copying the table to another tablespace,
-- dropping columns, or importing/exporting the table in question.
--- Run this script in SQL*Plus with a DBA account.
@@save_sqlplus_settings
set verify off
prompt
prompt
accept
accept
prompt
prompt
prompt

table_dependencies.sql

column
column
column
column
column

OWNER format a20


TABLE_NAME format a25
TABLESPACE_NAME format a15
TABLE_OWNER format a20
COLUMN_NAME format a35

xOwner prompt 'Enter table owner: '


xTable prompt 'Enter table: '
Table Dependencies for &xOwner . &xTable

set linesize 130


set pagesize 60
prompt DESCRIPTION OF &xTable
column "Null?" format a8
column TYPE format a30
SELECT column_name AS Name,
DECODE (nullable,'N','Not Null') AS "Null?",
DECODE (data_type,'VARCHAR2',data_type||'('||data_length||')',
'NUMBER',data_type||'('||data_length||','||data_precision||')',
data_type) AS Type
FROM dba_tab_columns
WHERE owner=UPPER('&xOwner') AND table_name=UPPER('&xTable');
prompt PRIMARY KEY FOR &xTable
SELECT a.constraint_name AS pk_constraint_name,b.column_name,b.position
FROM dba_constraints a,dba_cons_columns b
WHERE a.constraint_type='P' AND a.owner=UPPER('&xOwner')

AND a.table_name=UPPER('&xTable') AND a.constraint_name=b.constraint_name


ORDER BY position;
prompt INDEXES ON &xTable
SELECT INDEX_NAME,UNIQUENESS,TABLESPACE_NAME,INITIAL_EXTENT,NEXT_EXTENT,
MIN_EXTENTS,MAX_EXTENTS,PCT_INCREASE
FROM dba_indexes
WHERE owner = UPPER('&xOwner') AND table_name=UPPER('&xTable')
ORDER BY index_name;
prompt INDEX COLUMNS FOR &xTable
SELECT index_name,column_name,column_position
FROM dba_ind_columns
WHERE index_owner=UPPER('&xOwner') AND index_name IN
(SELECT index_name FROM dba_indexes WHERE owner = UPPER('&xOwner')
AND table_name=UPPER('&xTable'))
ORDER BY index_name,column_position;
prompt CHECK CONSTRAINTS FOR &xTable
column SEARCH_CONDITION format a40
column R_OWNER format a20
SELECT constraint_name,search_condition
FROM dba_constraints
WHERE owner=UPPER('&xOwner') AND table_name=UPPER('&xTable') AND constraint_type
= 'C'
ORDER BY constraint_type,constraint_name;
prompt F.K. REFERENCES FOR &xTable
column DELETE_RULE format a11
SELECT constraint_name,r_constraint_name,delete_rule
FROM dba_constraints
WHERE owner=UPPER('&xOwner') AND table_name=UPPER('&xTable') AND constraint_type
='R';
prompt TABLES &xTable REFERS TO
SELECT c.owner,c.table_name,c.constraint_name
FROM dba_constraints c
WHERE c.constraint_name IN (SELECT x.r_constraint_name
FROM dba_constraints x
WHERE x.owner=UPPER('&xOwner')
AND x.table_name=UPPER('&xTable')
AND x.constraint_type='R');
prompt F.K. REFERENCES TO &xTable
SELECT c.owner,c.table_name,c.constraint_name
FROM dba_constraints c
WHERE c.constraint_type='R' AND c.r_owner=UPPER('&xOwner')
AND c.r_constraint_name IN
(SELECT x.constraint_name
FROM dba_constraints x
WHERE x.owner=UPPER('&xOwner')
AND x.table_name=UPPER('&xTable')
AND x.constraint_type='P');
prompt OTHER DEPENDENCIES ON &xTable
SELECT owner,name,type
FROM dba_dependencies
WHERE referenced_owner=UPPER('&xOwner')
AND referenced_name=UPPER('&xTable');

@@sqlplus_settings
set echo on

#############

[LNP2B2U2]oracle@crm2u2 $ cat sga_anal.sql


set echo off
/*===================================================================
||
|| Filename:
sga_anal.sql
||
|| Views:
||
v$sgastat
||
v$shared_pool_reserved
||
v$shared_pool_reserved
||
v$shared_pool_reserved
||
v$sgastat
||
v$sgastat
||
v$sgastat
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$sga_dynamic_components
||
v$parameter
||
v$parameter
||
v$parameter
||
dba_objects
||
dba_objects
||
V$SGA_RESIZE_OPS
||
V$SGA_RESIZE_OPS
||
V$SGA_RESIZE_OPS
||
V$SGA_RESIZE_OPS
||
V$SGA_RESIZE_OPS
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
||
===================================================================*/
set echo off
@@save_sqlplus_settings
set lines 132
--set pages 5
set feedback ON
set linesize 132
set pagesize 132
set trimspool ON

col "Cache Size - Current (Mb)"


format 99999 head "Cache|Size|Curnt|(MB)
"
col "Cache Size - Minimum (Mb)"
format 99999 head "Cache|Size|Min|(MB)"
col "No.Cache Grows in 7 days"
format 99999 head "Numbr|Cache|Grows|in
7d"
col "Shared Pool - Current (Mb)"
format 99999 head "Share|Pool|Curnt|(MB)
"
col "Shared Pool - Minimum (Mb)"
format 99999 head "Share|Pool|Min|(MB)"
col "Shared Pool - Free (Mb)"
format 99999 head "Share|Pool|Free|(MB)"
col "No.Shared Pool Grows in 7days"
format 99999 head "Numbr|Share|Pool|Grow
s|Last|7 days"
col "Reserved Pool - Size(Mb)"
format 99999 head "Resrv|Pool|Size|(MB)"
col "Reserved Pool - Free (Mb)"
format 99999 head "Resrv|Pool|Free|(MB)"
col "Reserved Pool - Req Failures"
format 99999 head "Resrv|Pool|Req|Failr"
col "Java Pool- Current (Mb)"
format 99999 head "Java|Pool|Curnt|(MB)"
col "Java Pool- Minimum (Mb)"
format 99999 head "Java|Pool|Min|(MB)"
col "Java Pool - Free (Mb)"
format 99999 head "Java|Pool|Free|(MB)"
col "No.Java Pool Grows Last 7 days"
format 99999 head "Numbr|Java|Pool|Grows
|Last|7 days"
col "No.of non-SYS JAVA objects"
format 99999 head "Numbr|non-|SYS|Java|O
bjct"
col "No.of SYS JAVA objects"
format 99999 head "Numbr|SYS|Java|Objct"
col "Large Pool - Current (Mb)"
format 99999 head "Large|Pool|Curnt|(MB)
"
col "Large Pool - Minimum (Mb)"
format 99999 head "Large|Pool|Min|(MB)"
col "Large Pool - Free (Mb)"
format 99999 head "Large|Pool|Free|(MB)"
col "No.Large Pool Grows in 7 days"
format 99999 head "Numbr|Large|Pool|Grow
s|Last|7 days"
col "Streams Pool - Current (Mb)"
format 99999 head "Stream|Pool|Curnt|(MB
)"
col "Streams Pool - Minimum (Mb)"
format 99999 head "Stream|Pool|Min|(MB)"
col "Streams Pool - Free (Mb)"
format 99999 head "Stream|Pool|Free|(MB)
"
col "No.Streams Pool Grows in 7days"
format 99999 head "Numbr|Stream|Pool|Gro
ws|Last|7 days"
col "Keep Cache (Mb)"
format 99999 head "Keep|Cache|(MB)"
col "SGA Max Size (Mb)"
format 99999 head "SGA|Max|Size|(MB)"
col "SGA Target (Mb)"
format 99999 head "SGA|Target|(MB)"
col "Sum Cache+Pools - Minimum (Mb)"
format 99999 head "SUM|Cache|+Pool|Min|(
MB)"
col "Sum Cache+Pools - Current (Mb)"
format 99999 head "SUM|Cache|+Pool|Curnt
|(MB"
col Suggested_SGA_Target
format 99999 head "Suggd|SGA|Target"
col Suggested_SGA_Max_Size
format 99999 head "Suggd|SGA|Max|Size"
col Suggested_Shared_Pool_Res_Size
format 99999 head "Suggd|Share|Pool|Res|
Size"
SELECT db_cache_size_cur/1024/1024 as "Cache Size - Current (Mb)",
db_cache_size_min/1024/1024 as "Cache Size - Minimum (Mb)",
num_db_cache_grows as "No.Cache Grows in 7 days",
shared_pool_size_cur/1024/1024 as "Shared Pool - Current (Mb)",
shared_pool_size_min/1024/1024 as "Shared Pool - Minimum (Mb)",
Shared_Pool_Free_Mb as "Shared Pool - Free (Mb)",
num_shared_pool_grows as "No.Shared Pool Grows in 7days",
Reserved_Pool_Size_Mb
as "Reserved Pool - Size(Mb)",
Reserved_Pool_Free_Mb
as "Reserved Pool - Free (Mb)" ,
Reserved_Pool_Req_Failures as "Reserved Pool - Req Failures",
java_pool_size_cur/1024/1024 as "Java Pool- Current (Mb)",

java_pool_size_min/1024/1024 as "Java Pool- Minimum (Mb)",


java_pool_free_mb
as "Java Pool - Free (Mb)",
num_java_pool_grows
as "No.Java Pool Grows Last 7 days",
num_non_sys_owned_java_objs as "No.of non-SYS JAVA objects",
num_sys_owned_java_objs
as "No.of SYS JAVA objects",
large_pool_size_cur/1024/1024 as "Large Pool - Current (Mb)",
large_pool_size_min/1024/1024 as "Large Pool - Minimum (Mb)",
large_pool_free_mb
as "Large Pool - Free (Mb)",
num_large_pool_grows
as "No.Large Pool Grows in 7 days",
streams_pool_size_cur/1024/1024 as "Streams Pool - Current (Mb)",
streams_pool_size_min/1024/1024 as "Streams Pool - Minimum (Mb)",
streams_pool_free_mb
as "Streams Pool - Free (Mb)",
num_streams_pool_grows as "No.Streams Pool Grows in 7days",
keep_cache_size/1024/1024 as "Keep Cache (Mb)",
sga_max_size/1024/1024
as "SGA Max Size (Mb)",
sga_target/1024/1024
as "SGA Target (Mb)",
(db_cache_size_min+shared_pool_size_min+java_pool_size_min+large_pool_size
_min+streams_pool_size_min)/1024/1024
as "Sum Cache+Pools - Minimum (Mb)",
(db_cache_size_cur+shared_pool_size_cur+java_pool_size_cur+large_pool_size
_cur+streams_pool_size_cur)/1024/1024
as "Sum Cache+Pools - Current (Mb)",
( (db_cache_size_cur+shared_pool_size_cur+java_pool_size_cur+large_pool_s
ize_cur+streams_pool_size_cur)/1024/1024 ) * 1.2 as Suggested_SGA_Target,
( ( (db_cache_size_cur+shared_pool_size_cur+java_pool_size_cur+large_pool
_size_cur+streams_pool_size_cur)/1024/1024 ) * 1.2 ) * 1.2 as Suggested_SGA_Max_
Size,
CASE
WHEN Reserved_Pool_Req_Failures > 0
THEN
CASE
WHEN ( Reserved_Pool_Size_Mb < 0.1 * (shared_pool_size_cur/1024/
1024) ) -- i.e less than 10% of Current Shared Pool
THEN 0.1 * (shared_pool_size_cur/1024/1024)
WHEN ( Reserved_Pool_Size_Mb >= 0.1 * (shared_pool_size_cur/1024
/1024) ) -- i.e already more 10%, increase by 5%
THEN Reserved_Pool_Size_Mb + ( Reserved_Pool_Size_Mb * 1.05 )
END
ELSE
null
END as Suggested_Shared_Pool_Res_Size
FROM
( SELECT
( select round(bytes/1024/1024,2)
from v$sgastat
where pool='shared pool'
and name like 'free%' ) as Shared_Pool_Free_Mb,
( select round( (free_space+used_space)/1024/1024,0) from v$shared_pool_re
served ) as Reserved_Pool_Size_Mb,
( select round( free_space/1024/1024,2)
from v$shared_pool_re
served ) as Reserved_Pool_Free_Mb ,
( select request_failures
from v$shared_pool_re
served ) as Reserved_Pool_Req_Failures,
( select round(bytes/1024/1024,2)
from v$sgastat
where pool='java pool'
and name like 'free%' ) as Java_Pool_Free_Mb,
( select round(bytes/1024/1024,2)
from v$sgastat
where pool='large pool'

and name like 'free%' ) as Large_Pool_Free_Mb,


( select round(bytes/1024/1024,2)
from v$sgastat
where pool='streams pool'
and name like 'free%' ) as Streams_Pool_Free_Mb,
( select current_size from v$sga_dynamic_components where component='DEFAU
LT buffer cache' ) as db_cache_size_cur,
( select current_size from v$sga_dynamic_components where component='share
d pool')
as shared_pool_size_cur,
( select current_size from v$sga_dynamic_components where component='java
pool')
as java_pool_size_cur,
( select current_size from v$sga_dynamic_components where component='large
pool' ) as large_pool_size_cur,
( select current_size from v$sga_dynamic_components where component='strea
ms pool' ) as streams_pool_size_cur,
( select min_size from v$sga_dynamic_components where component='DEFAULT b
uffer cache' ) as db_cache_size_min,
( select min_size from v$sga_dynamic_components where component='shared po
ol') as shared_pool_size_min,
( select min_size from v$sga_dynamic_components where component='java pool
') as java_pool_size_min,
( select min_size from v$sga_dynamic_components where component='large poo
l' ) as large_pool_size_min,
( select min_size from v$sga_dynamic_components where component='streams p
ool' ) as streams_pool_size_min,
( select value from v$parameter where name='sga_target' )
as sga_targ
et,
( select value from v$parameter where name='sga_max_size' )
as sga_max_
size,
( select value from v$parameter where name='db_keep_cache_size' )
as ke
ep_cache_size,
( select count(*) from dba_objects where object_type LIKE '%JAVA%' and
owner ='SYS' ) as num_sys_owned_java_objs,
( select count(*) from dba_objects where object_type LIKE '%JAVA%' and
owner !='SYS' ) as num_non_sys_owned_java_objs,
( select count(*) from V$SGA_RESIZE_OPS
where component = 'DEFAULT buffer cache'
and trunc(start_time) > sysdate-7
and oper_type='GROW'
and nvl(oper_mode,'X') !='MANUAL'
) as num_db_cache_grows,
( select count(*) from V$SGA_RESIZE_OPS
where component = 'shared pool'
and trunc(start_time) > sysdate-7
and oper_type='GROW'
and nvl(oper_mode,'X') !='MANUAL'
) as num_shared_pool_grows,
( select count(*) from V$SGA_RESIZE_OPS
where component = 'java pool'
and trunc(start_time) > sysdate-7
and oper_type='GROW'
and nvl(oper_mode,'X') !='MANUAL'
) as num_java_pool_grows,
( select count(*) from V$SGA_RESIZE_OPS
where component = 'streams pool'
and trunc(start_time) > sysdate-7
and oper_type='GROW'
and nvl(oper_mode,'X') !='MANUAL'
) as num_streams_pool_grows,
( select count(*) from V$SGA_RESIZE_OPS

where component = 'large pool'


and trunc(start_time) > sysdate-7
and oper_type='GROW'
and nvl(oper_mode,'X') !='MANUAL'
) as num_large_pool_grows
FROM dual
) x
/
@@sqlplus_settings
set echo on

###########
[LNP2B2U2]oracle@crm2u2 $ cat shared_pool_advise.sql
-- ************************************************
-- Display shared pool advice
-- ************************************************
set lines 132
set pages 999
prompt
prompt The recommendation is normally the Pool Size for the highest value of Est
|Time|Saved|(sec)
prompt If there are multiple records then choose the lowest Pool Size for the hi
ghest value of Est|Time|Saved|(sec)
column
c1
heading 'Pool |Size(M)'
column
c2
heading 'Size|Factor'
column
c3
heading 'Est|LC(M) '
column
c4
heading 'Est LC|Mem. Obj.'
column
c5
heading 'Est|Time|Saved|(sec)'
column
c6
heading 'Est|Parse|Saved|Factor'
column c7
heading 'Est|Object Hits' format 999,999,999,999
SELECT
spa.shared_pool_size_for_estimate c1,
spa.shared_pool_size_factor
c2,
spa.estd_lc_size
c3,
spa.estd_lc_memory_objects
c4,
spa.estd_lc_time_saved
c5,
spa.estd_lc_time_saved_factor
c6,
spa.estd_lc_memory_object_hits
c7,
DECODE(spr.shared_pool_size_for_estimate,NULL,DECODE(spa.shared_pool_size_fac
tor,1,'<====Current Shared Pool Size',NULL),DECODE(spa.shared_pool_size_factor,1
,'<====Current and Recommended Shared Pool Size','<====Recommended Shared Pool S
ize')) Recommendation
FROM
v$shared_pool_advice spa,
(
SELECT MIN(shared_pool_size_for_estimate) shared_pool_size_for_estimate
FROM
v$shared_pool_advice
WHERE estd_lc_time_saved =
(
SELECT MAX(estd_lc_time_saved)
FROM
v$shared_pool_advice)

) spr
WHERE spa.shared_pool_size_for_estimate = spr.shared_pool_size_for_estimate(+)
ORDER BY 1
/

#############
[LNP2B2U2]oracle@crm2u2 $ cat tablespace_gfreespce11g.sql
set echo off
@@save_sqlplus_settings.sql
set lines 140 pages 999 trim on feed off verify off
col TSPACE_LEN new_value TSPACE_LEN noprint
SELECT CASE WHEN MAX(LENGTH(Tablespace_name)) > 30 THEN 'a132' ELSE 'a'||MAX(LE
NGTH(Tablespace_name)) END TSPACE_LEN
FROM
dba_tablespaces;
break on report
compute Sum LABEL SUM of TOT_AVAIL_SIZE on report
compute Sum LABEL SUM of TOT_SPACE_USED on report
compute Sum LABEL SUM of TOT_FREE_SPACE on report
col NO_OF_CHUNKS_AVAIL
col LARGEST_CHUNK_AVAIL
col TOT_AVAIL_SIZE
col TOT_SPACE_USED
col TOT_FREE_SPACE
col TABLESPACE_NAME
col PCT_USED
col IncrmntBytes
ES(M)"
--col IncrmntBytes
ES(M)"
col rcb_alloc
col rcb_used
col contents
col allocation_type
col extent_management
col assm
col bigfile
ACCEPT TSpace_Name CHAR
[ALL] : " default '%'

format
format
format
format
format
format
format
format

999,999 Head "FRAGMENTS"


9,999,999
Head "LARGEST|CHUNK|AVAIL(M)"
9,999,999
Head "TOTAL|AVAILABLE|SIZE(M)"
9,999,999
Head "TOTAL|SPACE|USED(M)"
9,999,999
Head "TOTAL|SPACE|FREE(M)"
&Tspace_Len
Head "TABLESPACE_NAME"
a4
Head "PCT|USED"
a13
Head "AUTOEXTEND|MAX ALLOWED|BYT

format 999,999
format
format
format
format
format
format
format
PROMPT

Head "AUTOEXTEND|MAX ALLOWED|BYT

9,999,999
Head "RECYCLE|ALLOC(M)"
9,999,999
Head "RECYCLE|USED(M)"
a4
Head "CONT"
a4
Head "ALLC|TYPE"
a5
Head "EXT|MGMNT"
a4
a4
Head "BIG|FILE"
"Enter a tablespace_name or press return for all

SELECT ts.tablespace_name,
DECODE(df_free_used.tablespace_name,NULL,SUM(tf_free_used.TOT_AVAIL_SIZE
),SUM(df_Free_Used.TOT_AVAIL_SIZE)) TOT_AVAIL_SIZE,
DECODE(df_free_used.tablespace_name,NULL,SUM(tf_Free_Used.TOT_AVAIL_SIZE
-tf_Free_Used.TOT_FREE_SPACE),SUM(df_Free_Used.TOT_AVAIL_SIZE-df_Free_Used.TOT_F
REE_SPACE)) TOT_SPACE_USED,
DECODE(df_free_used.tablespace_name,NULL,SUM(tf_Free_Used.TOT_FREE_SPACE
),SUM(df_Free_Used.TOT_FREE_SPACE)) TOT_FREE_SPACE,
DECODE(df_free_used.tablespace_name,NULL,LPAD(SUM(tf_free_used.pct_used)
||'%',4,' '),LPAD(SUM(df_free_used.pct_used)||'%',4,' ')) PCT_USED,
AVG(rcbin.rcb_alloc) RCB_ALLOC,
-AVG(rcbin.rcb_used) RCB_USED,
DECODE(df_free_used.tablespace_name,NULL,0,SUM(df_Free_Used.LARGEST_CHUN

K_AVAIL)) LARGEST_CHUNK_AVAIL,
DECODE(df_free_used.tablespace_name,NULL,0,SUM(df_Free_Used.NO_OF_CHUNKS
_AVAIL)) NO_OF_CHUNKS_AVAIL ,
SUBSTR(ts.contents,1,4) Contents,
SUBSTR(ts.allocation_type,1,4) Allocation_Type,
SUBSTR(ts.extent_management,1,5) Extent_Management,
DECODE(ts.SEGMENT_SPACE_MANAGEMENT,'AUTO','YES','NO') ASSM,
Bigfile ,
CASE WHEN autoextend.autoextensible IS NULL THEN 'NO '||LPAD(' 0',10,' '
) ELSE autoextend.autoextensible||LPAD(TO_CHAR(ROUND(SUM(df_Free_Used.TOT_AVAIL_
SIZE),0)+round(sum(df_free_used.IncrmntBytes),0)),10,' ') END IncrmntBytes
FROM
dba_tablespaces ts,
-- Calculate Free Space and Used Space for Datafiles
(
SELECT free_used.tablespace_name,
SUM(free_used.TOT_AVAIL_SIZE) TOT_AVAIL_SIZE,
SUM(free_used.TOT_FREE_SPACE) TOT_FREE_SPACE,
CASE WHEN SUM(free_used.TOT_AVAIL_SIZE-free_used.TOT_FREE_SPACE)
> 0 OR SUM(free_used.TOT_AVAIL_SIZE) > 0 THEN
ROUND((SUM(free_used.TOT_AVAIL_SIZE-free_used.TOT_FREE_SPACE)/SU
M(free_used.TOT_AVAIL_SIZE))*100,0) ELSE 0 END PCT_USED,
SUM(free_used.LARGEST_CHUNK_AVAIL) LARGEST_CHUNK_AVAIL,
SUM(free_used.NO_OF_CHUNKS_AVAIL) NO_OF_CHUNKS_AVAIL,
SUM(Incrmntbytes) INCRMNTBYTES
FROM
(
SELECT tablespace_name,
0 TOT_AVAIL_SIZE,
SUM(bytes/1048576) TOT_FREE_SPACE,
MAX(bytes/1048576) LARGEST_CHUNK_AVAIL,
COUNT(*) NO_OF_CHUNKS_AVAIL,
0 IncrmntBytes
FROM dba_free_space a
GROUP BY tablespace_name
UNION
SELECT tablespace_name,
SUM(bytes/1048576) TOT_AVAIL_SIZE,
0 TOT_FREE_SPACE,
0 LARGEST_CHUNK_AVAIL,
0 NO_OF_CHUNKS_AVAIL,
SUM(DECODE(maxbytes,0,0,(maxbytes-bytes)/1048576))
FROM dba_data_files f
GROUP BY tablespace_name) free_used
GROUP BY Tablespace_name
) df_free_used,
-- Calculate Free Space and Used Space for Tempfiles
(
SELECT free_used.tablespace_name,
SUM(free_used.TOT_AVAIL_SIZE) TOT_AVAIL_SIZE,
SUM(free_used.TOT_FREE_SPACE) TOT_FREE_SPACE,
SUM(free_used.TOT_SPACE_USED) TOT_SPACE_USED,
CASE WHEN SUM(free_used.TOT_SPACE_USED) > 0 OR SUM(free_used.TOT
_AVAIL_SIZE) > 0 THEN
ROUND((SUM(free_used.TOT_SPACE_USED)/SUM(free_used.TOT_AVAIL_SIZ
E))*100,0) ELSE 0 END PCT_USED
FROM
(
SELECT ss.tablespace_name,
AVG((total_blocks_avail*dtf.block_size)/1048576) TOT_AVA
IL_SIZE,
AVG((Total_Blocks_avail*dtf.block_size)/1048576) - SUM((

used_blocks*block_size)/1048576) TOT_FREE_SPACE,
SUM(used_blocks*block_size)/1048576 TOT_SPACE_USED
FROM
gv$sort_segment ss,
(
SELECT tf.tablespace_name,
AVG(t.Block_size) block_size,
SUM(tf.blocks) Total_Blocks_Avail
FROM
Dba_temp_files tf,
dba_tablespaces t
WHERE tf.tablespace_name
=
t.tablespace_nam
e
GROUP BY
tf.tablespace_name
) dtf
WHERE ss.Tablespace_name
= dtf.tablespace_name
GROUP BY
ss.tablespace_name
)
free_used
GROUP BY free_used.tablespace_name,
free_used.TOT_SPACE_USED,
free_used.TOT_AVAIL_SIZE
) tf_free_used,
-- Calculate space used by recyclebin
(
SELECT tablespace_name,
SUM(Bytes/1048576) RCB_ALLOC,
SUM(space*8192)/1048576 RCB_USED
FROM
dba_segments
s,
dba_recyclebin r
WHERE
s.segment_name =
r.object_name
GROUP BY tablespace_name
) RCBIN,
(
SELECT distinct tablespace_name,autoextensible
FROM
dba_data_files
WHERE autoextensible =
'YES'
) autoextend
WHERE ts.tablespace_name
=
df_Free_Used.tablespace_name(+)
AND
ts.tablespace_name
=
tf_Free_Used.tablespace_name(+)
AND
ts.tablespace_name
=
rcbin.tablespace_name(+)
AND
ts.tablespace_name
LIKE
UPPER('&TSPace_Name.%')
AND
ts.tablespace_name
=
autoextend.tablespace_name(+)
GROUP BY ts.tablespace_name,
df_free_used.tablespace_name,
ts.contents,
ts.allocation_type,
ts.extent_management,
ts.SEGMENT_SPACE_MANAGEMENT,
ts.bigfile,
autoextend.autoextensible,
df_free_used.IncrmntBytes
ORDER BY 1
/
#############
[LNP2B2U2]oracle@crm2u2 $ cat rollback_progress.sql
-- will decrease until they become 0. By sampling the two measures at
-- different points of time, you can calculate how fast the rollback
-- is and when it is going to complete.

SELECT t.used_ublk, t.used_urec


FROM v$session s, v$transaction t
WHERE s.taddr=t.addr
and s.SID =:sid;
############
[LNP2B2U2]oracle@crm2u2 $ cat show_hparam.sql
set echo off
/*===================================================================
||
|| Filename:
show_hparam.sql
||
|| Views:
||
|| Details:
||
|| 26/04/11
Ray Metz
Created
||
===================================================================*/
@@save_sqlplus_settings
set lines 200
col name format a80
col description format a110 word_wrap
SELECT KSPPINM name,
KSPPDESC description
FROM sys.X$KSPPI
WHERE substr(KSPPINM,1,1) = '_';
@@save_sqlplus_settings
set echo on
########### os memory usage ##########
[LNNRDSP1]oracle@nrdsp1 $ cat omemuse.ksh
#!/usr/bin/sh
#
# Copyright 2001 Oracle Corporation
#
# program: omemuse (Oracle MEMory USagE)
# by Richard Gulledge
#
# modification history:
# date
by
comments
# ---------- -------- ---------------# 11/15/1999 rgulledg original program
# 04/16/2001 rgulledg minor usage check mods
#
usage()
{
echo "Usage: $0 [
echo "Usage: $0 [
echo "Usage: $0 [
echo " "
echo "specify 'S'
echo "specify 'B'
echo "specify 'h'

SB ]"
P <pid> ]"
h ]"
for Oracle shadow processes"
for Oracle background processes (includes shared memory SGA)"
for help"

echo " "


}
echo " "
#
# check usage
#
if [ $# = "0" ];then
usage;exit 1
fi
Parm1=$1
if [ $Parm1 = "h" ];then
echo "This script uses the Sun Solaris pmap command to determine memory usage"
echo "for Oracle server [B]ackground processes and/or [S]hadow processes."
echo "An individual [P]rocess can also be specified."
echo " "
echo "Although the Oracle server background processes memory usage should"
echo "remain fairly constant, the memory used by any given shadow process"
echo "can vary greatly. This script shows only a snapshot of the current"
echo "memory usage for the processes specified."
echo " "
echo "The 'B' option shows the sum of memory usage for all Oracle server"
echo "background processes, including shared memory like the SGA."
echo " "
echo "The 'S' option shows the sum of private memory usage by all"
echo "shadow processes. It does not include any shared memory like the"
echo "SGA since these are part of the Oracle server background processes."
echo " "
echo "The 'P' option shows memory usage for a specified process, broken"
echo "into two categories, private and shared. If the same executable"
echo "for this process was invoked again, only the private memory"
echo "would be allocated, the rest is shared with the currently running"
echo "process."
echo " "
usage;exit 1
fi
echo $Parm1|grep '[SBP]' > /dev/null
ParmFound=$?
if [ $ParmFound != "0" ];then
usage;exit 1
fi
echo $Parm1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
if [ $Parm1 != "P" ];then
usage;exit 1
fi
if [ "X$2" = "X" ];then
usage;exit 1
fi
Parm2=$2
echo $Parm2|grep '[^0-9]' > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
usage;exit 1
fi
PidOwner=`ps -ef | grep -v grep | grep $Parm2 | grep -v $0 | awk '{print $1}'`
CurOwner=`/usr/xpg4/bin/id -un`
if [ "X$PidOwner" != "X$CurOwner" ];then

echo "Not owner of pid $Parm2, or pid $Parm2 does not exist"
echo " "
usage;exit 1
fi
else
if [ "X${ORACLE_SID}" = "X" ];then
echo "You must set ORACLE_SID first"
usage;exit1
fi
fi
#
# initialize variables
#
Pmap="/usr/proc/bin/pmap"
SharUse="/tmp/omemuseS$$"
PrivUse="/tmp/omemuseP$$"
ShadUse="/tmp/omemuseD$$"
PidPUse="/tmp/omemusePP$$"
PidSUse="/tmp/omemusePS$$"
TotalShad=0
TotalShar=0
TotalPriv=0
PidPriv=0
PidShar=0
#
# shadow processes
#
echo $Parm1|grep S > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
ShadPrc="`ps -ef|grep -v grep|grep oracle$ORACLE_SID|awk '{print $2}'`"
echo "" > $ShadUse
for i in $ShadPrc;do
$Pmap $i | grep "read/write" | grep -v shared | \
awk '{print $2}' | awk -FK '{print $1}' >> $ShadUse
done
for i in `cat $ShadUse`;do
TotalShad=`expr $TotalShad + $i`
done
TotalShad=`expr $TotalShad "*" 1024`
echo "Total Shadow (bytes) : $TotalShad"
/bin/rm $ShadUse
fi
#
# non-shared portion of background processes
#
echo $Parm1|grep B > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
OrclPrc="`ps -ef|grep -v grep|grep ora_|grep $ORACLE_SID|awk '{print $2}'`"
BkgdPrc="`echo $OrclPrc|awk '{print $1}'`"
echo "" > $PrivUse
for i in $OrclPrc;do
$Pmap $i | grep "read/write" | grep -v shared | \
awk '{print $2}' | awk -FK '{print $1}' >> $PrivUse
done
for i in `cat $PrivUse`;do

TotalPriv=`expr $TotalPriv + $i`


done
TotalPriv=`expr $TotalPriv "*" 1024`
echo "Total Private (bytes) : $TotalPriv"
#
# shared portion of background processes
#
echo "" > $SharUse
$Pmap $BkgdPrc | grep "read/exec" | \
awk '{print $2}' | awk -FK '{print $1}' >> $SharUse
$Pmap $BkgdPrc | grep "shared" | \
awk '{print $2}' | awk -FK '{print $1}' >> $SharUse
for i in `cat $SharUse`;do
TotalShar=`expr $TotalShar + $i`
done
TotalShar=`expr $TotalShar "*" 1024`
echo "Total Shared (bytes) : $TotalShar"
/bin/rm $SharUse $PrivUse
fi
#
# non-shared portion of pid
#
echo $Parm1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
echo "" > $PidPUse
$Pmap $Parm2 | grep "read/write" | grep -v shared | \
awk '{print $2}' | awk -FK '{print $1}' >> $PidPUse
for i in `cat $PidPUse`;do
PidPriv=`expr $PidPriv + $i`
done
PidPriv=`expr $PidPriv "*" 1024`
echo "Total Private (bytes) : $PidPriv"
#
# shared portion of pid
#
echo "" > $PidSUse
$Pmap $Parm2 | grep "read/exec" | awk '{print $2}' | \
awk -FK '{print $1}' >> $PidSUse
$Pmap $Parm2 | grep "shared" | awk '{print $2}' | \
awk -FK '{print $1}' >> $PidSUse
for i in `cat $PidSUse`;do
PidShar=`expr $PidShar + $i`
done
PidShar=`expr $PidShar "*" 1024`
echo "Total Shared (bytes) : $PidShar"
/bin/rm $PidPUse $PidSUse
fi
#
# Display grand total
#
Gtotal="`expr $TotalShad + $TotalPriv + $TotalShar + $PidPriv + $PidShar`"
echo "
-----"
echo "Grand Total (bytes) : $Gtotal"
echo " "
[LNNRDSP1]oracle@nrdsp1 $

##########
[LNMRDD8]oracle@cbmrsd3b2 $ cat freespce10g.sql
set echo off
@@save_sqlplus_settings.sql
set lines 132 pages 999 trim on feed off verify off
ACCEPT TSpace_Name CHAR PROMPT "Enter a tablespace_name or press return for all
[ALL] : " default '%'
col TSPACE_LEN new_value TSPACE_LEN noprint
col SIZE_LEN new_value SIZE_LEN noprint
SELECT 'A'||MAX(TSPACE_LEN) TSPACE_LEN,
MAX(LPAD('9',SIZE_LEN,'9')) SIZE_LEN
FROM
(
SELECT MAX(LENGTH(t.Tablespace_name)) TSPACE_LEN,
MAX(LENGTH(ROUND(SUM(d.bytes/1024/1024),0))+3) SIZE_LEN
FROM
dba_tablespaces t,
dba_data_files d
WHERE t.Tablespace_name =d.Tablespace_name
AND
t.tablespace_name
LIKE
UPPER('&TSPace_Name.%')
GROUP BY bytes,t.tablespace_name
UNION
SELECT MAX(LENGTH(t.Tablespace_name)) TSPACE_LEN,
MAX(LENGTH(ROUND(SUM(d.bytes/1024/1024),0))+3) SIZE_LEN
FROM
dba_tablespaces t,
dba_temp_files d
WHERE t.Tablespace_name =d.Tablespace_name
AND
t.tablespace_name
LIKE
UPPER('&TSPace_Name.%')
GROUP BY bytes,t.tablespace_name
)
;
break on report
compute Sum LABEL SUM of TOT_AVAIL_SIZE on report
compute Sum LABEL SUM of TOT_SPACE_USED on report
compute Sum LABEL SUM of TOT_FREE_SPACE on report
col NO_OF_CHUNKS_AVAIL
col LARGEST_CHUNK_AVAIL
col TOT_AVAIL_SIZE
col TOT_SPACE_USED
col TOT_FREE_SPACE
col TABLESPACE_NAME
col PCT_USED
col IncrmntBytes
ES(M)"
--col IncrmntBytes
ES(M)"
col rcb_alloc
col rcb_used
col contents
col allocation_type
col extent_management
col assm
col status

format
format
format
format
format
format
format
format

99999
&SIZE_LEN
&SIZE_LEN
&SIZE_LEN
&SIZE_LEN
&Tspace_Len
a4
a13

Head
Head
Head
Head
Head
Head
Head
Head

"FRAG-|MENTS"
"LRGST|CHUNK|AVAIL|(M)"
"TOTAL|SPACE|AVAIL|(M)"
"TOTAL|SPACE|USED|(M)"
"TOTAL|SPACE|FREE|(M)"
"TABLE|SPACE|NAME"
"PCT|USED"
"AUTOEXTEND|MAX ALLOWED|BYT

format 999,999

Head "AUTOEXTEND|MAX ALLOWED|BYT

format
format
format
format
format
format
format

Head
Head
Head
Head
Head

&SIZE_LEN
&SIZE_LEN
a4
a4
a5
a4
a2

"RECYC|ALLOC|(M)"
"RECYC|USED|(M)"
"CONT"
"ALLC|TYPE"
"EXT|MGMNT"

Head "S|T|U|S"

SELECT ts.tablespace_name,
DECODE(df_free_used.tablespace_name,NULL,SUM(tf_free_used.TOT_AVAIL_SIZE
),SUM(df_Free_Used.TOT_AVAIL_SIZE)) TOT_AVAIL_SIZE,
DECODE(df_free_used.tablespace_name,NULL,SUM(tf_Free_Used.TOT_AVAIL_SIZE
-tf_Free_Used.TOT_FREE_SPACE),SUM(df_Free_Used.TOT_AVAIL_SIZE-df_Free_Used.TOT_F
REE_SPACE)) TOT_SPACE_USED,
DECODE(df_free_used.tablespace_name,NULL,SUM(tf_Free_Used.TOT_FREE_SPACE
),SUM(df_Free_Used.TOT_FREE_SPACE)) TOT_FREE_SPACE,
DECODE(df_free_used.tablespace_name,NULL,LPAD(SUM(tf_free_used.pct_used)
||'%',4,' '),LPAD(SUM(df_free_used.pct_used)||'%',4,' ')) PCT_USED,
AVG(rcbin.rcb_alloc) RCB_ALLOC,
-AVG(rcbin.rcb_used) RCB_USED,
DECODE(df_free_used.tablespace_name,NULL,0,SUM(df_Free_Used.LARGEST_CHUN
K_AVAIL)) LARGEST_CHUNK_AVAIL,
DECODE(df_free_used.tablespace_name,NULL,0,SUM(df_Free_Used.NO_OF_CHUNKS
_AVAIL)) NO_OF_CHUNKS_AVAIL ,
SUBSTR(ts.contents,1,4) Contents,
SUBSTR(ts.allocation_type,1,4) Allocation_Type,
SUBSTR(ts.extent_management,1,5) Extent_Management,
DECODE(ts.SEGMENT_SPACE_MANAGEMENT,'AUTO','YES','NO') ASSM,
DECODE(ts.status,'ONLINE','W','READ ONLY','RO',ts.status) STATUS,
CASE WHEN autoextend.autoextensible IS NULL THEN 'NO '||LPAD(' 0',10,' '
) ELSE autoextend.autoextensible||LPAD(TO_CHAR(ROUND(SUM(df_Free_Used.TOT_AVAIL_
SIZE),0)+round(sum(df_free_used.IncrmntBytes),0)),10,' ') END IncrmntBytes
FROM
dba_tablespaces ts,
-- Calculate Free Space and Used Space for Datafiles
(
SELECT free_used.tablespace_name,
SUM(free_used.TOT_AVAIL_SIZE) TOT_AVAIL_SIZE,
SUM(free_used.TOT_FREE_SPACE) TOT_FREE_SPACE,
CASE WHEN SUM(free_used.TOT_AVAIL_SIZE-free_used.TOT_FREE_SPACE)
> 0 OR SUM(free_used.TOT_AVAIL_SIZE) > 0 THEN
ROUND((SUM(free_used.TOT_AVAIL_SIZE-free_used.TOT_FREE_SPACE)/SU
M(free_used.TOT_AVAIL_SIZE))*100,0) ELSE 0 END PCT_USED,
SUM(free_used.LARGEST_CHUNK_AVAIL) LARGEST_CHUNK_AVAIL,
SUM(free_used.NO_OF_CHUNKS_AVAIL) NO_OF_CHUNKS_AVAIL,
SUM(Incrmntbytes) INCRMNTBYTES
FROM
(
SELECT tablespace_name,
0 TOT_AVAIL_SIZE,
SUM(bytes/1048576) TOT_FREE_SPACE,
MAX(bytes/1048576) LARGEST_CHUNK_AVAIL,
COUNT(*) NO_OF_CHUNKS_AVAIL,
0 IncrmntBytes
FROM dba_free_space a
GROUP BY tablespace_name
UNION
SELECT tablespace_name,
SUM(bytes/1048576) TOT_AVAIL_SIZE,
0 TOT_FREE_SPACE,
0 LARGEST_CHUNK_AVAIL,
0 NO_OF_CHUNKS_AVAIL,
SUM(DECODE(maxbytes,0,0,(maxbytes-bytes)/1048576))
FROM dba_data_files f
GROUP BY tablespace_name) free_used
GROUP BY Tablespace_name
) df_free_used,
-- Calculate Free Space and Used Space for Tempfiles
(

SELECT free_used.tablespace_name,
SUM(free_used.TOT_AVAIL_SIZE) TOT_AVAIL_SIZE,
SUM(free_used.TOT_FREE_SPACE) TOT_FREE_SPACE,
SUM(free_used.TOT_SPACE_USED) TOT_SPACE_USED,
CASE WHEN SUM(free_used.TOT_SPACE_USED) > 0 OR SUM(free_used.TOT
_AVAIL_SIZE) > 0 THEN
ROUND((SUM(free_used.TOT_SPACE_USED)/SUM(free_used.TOT_AVAIL_SIZ
E))*100,0) ELSE 0 END PCT_USED
FROM
(
SELECT ss.tablespace_name,
SUM((total_blocks_avail*dtf.block_size)/1048576) TOT_AVA
IL_SIZE,
SUM((Total_Blocks_avail*dtf.block_size)/1048576) - SUM((
used_blocks*block_size)/1048576) TOT_FREE_SPACE,
SUM(used_blocks*block_size)/1048576 TOT_SPACE_USED
FROM
v$sort_segment ss,
(
SELECT tf.tablespace_name,
AVG(t.Block_size) block_size,
SUM(tf.blocks) Total_Blocks_Avail
FROM
Dba_temp_files tf,
dba_tablespaces t
WHERE tf.tablespace_name
=
t.tablespace_nam
e
GROUP BY
tf.tablespace_name
) dtf
WHERE ss.Tablespace_name
= dtf.tablespace_name
GROUP BY
ss.tablespace_name
)
free_used
GROUP BY free_used.tablespace_name,
free_used.TOT_SPACE_USED,
free_used.TOT_AVAIL_SIZE
) tf_free_used,
-- Calculate space used by recyclebin
(
SELECT tablespace_name,
SUM(Bytes/1048576) RCB_ALLOC
FROM
dba_segments
s
WHERE
s.segment_name LIKE 'BIN$%'
GROUP BY tablespace_name
) RCBIN,
(
SELECT distinct tablespace_name,autoextensible
FROM
dba_data_files
WHERE autoextensible =
'YES'
) autoextend
WHERE ts.tablespace_name
=
df_Free_Used.tablespace_name(+)
AND
ts.tablespace_name
=
tf_Free_Used.tablespace_name(+)
AND
ts.tablespace_name
=
rcbin.tablespace_name(+)
AND
ts.tablespace_name
LIKE
UPPER('&TSPace_Name.%')
AND
ts.tablespace_name
=
autoextend.tablespace_name(+)
GROUP BY ts.tablespace_name,
df_free_used.tablespace_name,
ts.contents,
ts.allocation_type,
ts.extent_management,
ts.SEGMENT_SPACE_MANAGEMENT,
ts.status,
autoextend.autoextensible,
df_free_used.IncrmntBytes

ORDER BY 1
/
@sqlplus_settings.sql
set echo on

[LNFAARD1]oracle@fbiapld03 $ cat pga_target_advice.sql


set echo off
@@save_sqlplus_settings
set pages 40
select
trunc(pga_target_for_estimate/1024/1024)
pga_target_for_estimate,
to_char(pga_target_factor * 100,'999.9') ||'%'
pga_target_factor,
trunc(bytes_processed/1024/1024) bytes_processed,
trunc(estd_extra_bytes_rw/1024/1024) estd_extra_bytes_rw,
to_char(estd_pga_cache_hit_percentage,'999') || '%'
estd_pga_cache_hit_percentage,
estd_overalloc_count
from v$pga_target_advice
/
@@sqlplus_settings
set echo on
[LNFAARU1]oracle@fbiaplu03 $ cat hidden_params.sql
select
a.ksppinm
name,
b.ksppstvl
value,
b.ksppstdf
default,
decode
(a.ksppity, 1,
'boolean', 2,
'string', 3,
'number', 4,
'file', a.ksppity) type,
a.ksppdesc
description
from
sys.x$ksppi a,
sys.x$ksppcv b
where
a.indx = b.indx
and
a.ksppinm like '\_%' escape '\'
order by
name;
another one for hidden ########
set
col
col
col
col
col
col
col

lines 132
numb format 9999
name format a30 word_wrap
description format a30 word_wrap
value format a15 word_wrap
is_default format a5 HEAD "IS|DEFLT"
is_session_modifiable format a5 HEAD "IS|SESS|MODBL"
is_system_modifiable format a5 HEAD "IS|SYST|MODBL"

col is_modified format a5 HEAD "IS|MODFD"


col is_adjusted format a5 HEAD "IS|ADJD"
ACCEPT HIDDEN_PARAMETER CHAR PROMPT "Enter Hidden Parameter ===================>
"
select
nam.indx+1
numb,
nam.ksppinm
name,
val.ksppstvl
value,
nam.ksppity
type,
val.ksppstdf
is_default,
decode(bitand(nam.ksppiflg/256,1),
1,'TRUE',
'FALSE'
)
is_session_modifiable,
decode(bitand(nam.ksppiflg/65536,3),
1,'IMMED',
2,'DEFRD' ,
3,'IMMED',
'FALSE'
)
is_system_modifiable,
decode(bitand(val.ksppstvf,7),
1,'MODIFIED',
4,'SYSTEM MODIFIED',
'FALSE'
)
is_modified,
decode(bitand(val.ksppstvf,2),
2,'TRUE',
'FALSE'
)
is_adjusted,
nam.ksppdesc
description
from
x$ksppi
nam,
x$ksppsv
val
where
nam.indx = val.indx
and nam.ksppinm like LOWER('%&HIDDEN_PARAMETER%')
######### shrink analyze #####
set linesize 200
set pagesize 200
col
col
col
col

"Tablespace"
"Segment Name"
"Datafile Location"
"Highwater Mark (Mb)"

format a20
format a45 heading "Segment|Name"
format a50 heading "Datafile|Location"
heading "Highwater|Mark (Mb)"

select ddf.tablespace_name "Tablespace", ddf.file_name "Datafile Location", ddf.


bytes/(1024*1024) "Size (Mb)",
round(((hwm.maximum+de.blocks-1)*dbs.db_block_size)/(1024*1024),2) "Highw
ater Mark (Mb)",
de.owner||'.'||de.segment_name "Segment Name", de.segment_type "Type"
from dba_data_files ddf, (select file_id, max(block_id) maximum
from dba_extents
group by file_id) hwm,
dba_extents de, (select value db_block_size
from v$parameter
where name='db_block_size') dbs
where ddf.file_id = hwm.file_id

and de.file_id = hwm.file_id


and de.block_id = hwm.maximum
order by 1, 2, 6, 5 ;

You might also like