Wednesday, April 27, 2011

Scripts to find out SIZE of the DB

Query to find the DB size in Bytes.

select a.data_size+b.temp_size+c.redo_size "total_size"
from ( select sum(bytes) data_size
         from dba_data_files ) a,
     ( select nvl(sum(bytes),0) temp_size
         from dba_temp_files ) b,
     ( select sum(bytes) redo_size
         from sys.v_$log ) c;

Another query ("Free space" reports data files free space):

col "Database Size" format a20
col "Free space" format a20
select round(sum(used.bytes) / 1024 / 1024 /1024  ) || ' GB' "Database Size"
,      round(free.p / 1024 / 1024 / 1024 ) || ' GB' "Free space"
from (select bytes from v$datafile
      union all
      select bytes from v$tempfile
      union all
      select bytes from v$log) used
,    (select sum(bytes) as p from dba_free_space) free
group by free.p
/