Oracle DBA, How To, Error, Cause and Action

Showing posts with label DBA Report. Show all posts
Showing posts with label DBA Report. Show all posts

Check Tablespace Usage


set pagesize 100
set sqlnumber off
SELECT tbs.tablespace_name,
tot.bytes / 1024 total,
tot.bytes / 1024 -SUM(nvl(fre.bytes, 0)) / 1024 used,
SUM(nvl(fre.bytes, 0)) / 1024 free,
(1 -SUM(nvl(fre.bytes, 0)) / tot.bytes) *100 pct,
-- this give warning to high percentage usage tablespace
decode(greatest
      ((1 -SUM(nvl(fre.bytes, 0)) / tot.bytes) *100, 90), 
      90, '', '*') pct_warn
FROM dba_free_space fre,
(SELECT tablespace_name,
SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name)
tot,
dba_tablespaces tbs
WHERE tot.tablespace_name = tbs.tablespace_name
AND fre.tablespace_name(+) = tbs.tablespace_name
GROUP BY tbs.tablespace_name,
tot.bytes / 1024,
tot.bytes
ORDER BY 5, 1;