early_warning_space.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 a24 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 System, data, and index tablespaces should not have less than 10% free space.
column tablespace_name format a15 trunc heading "TABLESPACE"
column used_bytes format 999,999,999,999 heading "USED BYTES"
column free_bytes format 999,999,999,999 heading "FREE BYTES"
column pctfree format 999.9 heading "PCTFREE"
column largest format 9,999,999,999 heading "LARGEST EXT"
column free_extents format 9999 heading "FREE|FRGS"
select tablespace_name,
used_bytes,
free_bytes,
100*free_bytes/(used_bytes+free_bytes) "pctfree",
largest,
free_extents
from space_report
/
prompt
prompt
spool off
drop table max_next
/
drop table space_report
/
exit