Ray Script
Ray Script
"Tablespace"
"Segment Name"
"Datafile Location"
"Highwater Mark (Mb)"
format a20
format a45 heading "Segment|Name"
format a50 heading "Datafile|Location"
heading "Highwater|Mark (Mb)"
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
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;
/
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
-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
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
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.
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._×tamp..log
PROMPT
PROMPT
COLUMN PCT_USED DEFAULT
UNDEFINE TSPACE
SET ECHO ON
sid
oracle_username
right
os_username
right
session_program
FORMAT 999
FORMAT a12
HEADING 'SID'
HEADING 'Oracle User'
FORMAT a9
FORMAT a18
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
===============>
==============
@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
WHEN
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 '%'
===================
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
-- 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.
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
-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
------- ---------------- -------------------- -------------- ------- ----------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
-- 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._×tamp..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);
**********"
Log Buffers
**********" skip 1
Latch Information
**********" skip 1
*****
*****"
rem ------------------------------------------------------------rem
Fragmentation Need
rem ------------------------------------------------------------set
set
set
set
heading on
termout on
pagesize 66
line 132
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
**
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)"
#################
[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
'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
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
AND
AND
AND
AND
AND
UNION
SELECT
FROM
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
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
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
############
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
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
'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
@@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
format 999,999
format
format
format
format
format
format
format
PROMPT
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.
SB ]"
P <pid> ]"
h ]"
for Oracle shadow processes"
for Oracle background processes (includes shared memory SGA)"
for help"
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
##########
[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
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
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"
"Tablespace"
"Segment Name"
"Datafile Location"
"Highwater Mark (Mb)"
format a20
format a45 heading "Segment|Name"
format a50 heading "Datafile|Location"
heading "Highwater|Mark (Mb)"