Thursday, February 14, 2008

Monitoring Oracle tablespace usage

Maybe some of us need to monitor Oracle tablespace usage on our DB Server. Here is some script that give a report about tablespace usage.

column "Tablespace" format a13
column "Used MB" format 99,999,999
column "Free MB" format 99,999,999
colimn "Total MB" format 99,999,999

select
fs.tablespace_name "Tablespace",
(df.totalspace - fs.freespace) "Used MB",
fs.freespace "Free MB",
df.totalspace "Total MB",
round(100 * (fs.freespace / df.totalspace)) "Pct. Free"
from
(select
tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
from
dba_data_files
group by
tablespace_name
) df,
(select
tablespace_name,
round(sum(bytes) / 1048576) FreeSpace
from
dba_free_space
group by
tablespace_name
) fs
where
df.tablespace_name = fs.tablespace_name;

This script can be set to be run every day (with scheduler or crontab), and the result will be emailed to DBA.

1 comment:

Unknown said...

Very helpful script. Thank you!