Database 11g

Thursday, October 29, 2015

To check Tablespaces that are >=80% full, and how much to add to make them 80% again



SQL> set pages 999 lines 100
SQL> col        "Tablespace"    for a50
SQL> col        "Size MB"       for 999999999
SQL> col        "%Used"         for 999
SQL> col        "Add (80%)"     for 999999
SQL> select     tsu.tablespace_name "Tablespace"
  2  ,  ceil(tsu.used_mb) "Size MB"
  3  ,  100 - floor(tsf.free_mb/tsu.used_mb*100) "%Used"
  4  ,  ceil((tsu.used_mb - tsf.free_mb) / .5) - tsu.used_mb "Add (50%)"
  5  from       (select tablespace_name, sum(bytes)/1024/1024 used_mb
  6     from    dba_data_files group by tablespace_name) tsu
  7  ,          (select ts.tablespace_name
  8     ,       nvl(sum(bytes)/1024/1024, 0) free_mb
  9     from    dba_tablespaces ts, dba_free_space fs
 10     where   ts.tablespace_name = fs.tablespace_name (+)
 11     group by ts.tablespace_name) tsf
 12  where      tsu.tablespace_name = tsf.tablespace_name (+)
 13  and        100 - floor(tsf.free_mb/tsu.used_mb*100) >= 50
 14  order      by 3,4
 15  ;

Tablespace                                            Size MB        %Used              Add (50%)
-------------------------------------------------- ---------- ----- ------------------------------
SYSTEM                                                5120                60                  1015
USERS                                                   30720              63                  7408


Happy Learning ....





No comments:

Post a Comment