Cheeky Cockatoo

Life Advice and Stories, Travel, Oracle Tech, Good Food and More

early_warning_extents.sql

Download Script

set feedback off
set verify off
set echo on 
set linesize 80
set pagesize 24
define db = &&1
define outfile = &&2
column segment_name	format a29 trunc head "Segment|Name"
column segment_type	format a10 trunc head "Segment|Type"
drop table space_report
/
drop table max_next
/
column db new_value new_db
column time new_value new_time
select upper('&&db') db, to_char(sysdate,'DD-MON-YYYY HH24:MI') time from dual
/
spool &&outfile
prompt &&new_db Database Space Report
prompt &&new_time
create table space_report 
(tablespace_name char(30),
 used_bytes      number,
 free_bytes      number,
 largest         number,
 free_extents    number)
/
insert into space_report (tablespace_name, used_bytes)
select tablespace_name, sum(dba_extents.bytes)
from dba_extents
group by tablespace_name
/
insert into space_report (tablespace_name, used_bytes)
 (select TABLESPACE_NAME, 0 from dba_tablespaces
  where TABLESPACE_NAME not in 
  (select distinct TABLESPACE_NAME from dba_extents)
 )
/
update space_report sr set (free_bytes, largest, free_extents) =
(select sum(fs.bytes), max(bytes), count(*) from dba_free_space fs
 where rtrim(sr.tablespace_name) = fs.tablespace_name
 group by fs.tablespace_name)
/
prompt
prompt
prompt Objects extended to more than 60% but less than 100% of max_extents,
prompt excluding cache segments:
column owner		format a15 trunc
column MAX_EXTS		format a7 heading "Max|Ext"
select segment_name, 
       segment_type,
       owner,
       extents,
       decode ( max_extents, 2147483645, 'NoLimit', max_extents ) MAX_EXTS
from dba_segments
where extents/max_extents > .6
  and extents <> max_extents
  and segment_type <> 'CACHE'
order by segment_name
/
prompt
prompt
spool off
drop table max_next
/
drop table space_report
/
exit