Sep 28, 2011

Query to get Used and Total size of Oracle Database

  Following query will return the  Used and Total size of the database based on the table spaces of the database

  select ROUND(dbspace.u+logspace.aa,2) "USED SIZE", ROUND(dbspace.t+logspace.aa,2) "TOTAL SIZE"
from
(select sum(Free_space) f,sum(Used_space) u,sum(total_space) t
from
(SELECT Total.name "Tablespace Name",
       nvl(Free_space, 0) Free_space,
       nvl(total_space-Free_space, 0) Used_space,
       total_space
FROM
  (select tablespace_name, sum(bytes/1024/1024/1024) Free_Space
     from sys.dba_free_space
    group by tablespace_name
  ) Free,
  (select b.name,  sum(bytes/1024/1024/1024) TOTAL_SPACE
     from sys.v_$datafile a, sys.v_$tablespace B
    where a.ts# = b.ts#
    group by b.name
  ) Total
WHERE Free.Tablespace_name(+) = Total.name
ORDER BY Total.name)) dbspace,
(select sum(bytes)/1024/1024/1024 aa from v$log) logspace

0 comments: