Thursday, November 1, 2012

Sql to get the Database Size

Database is a collection of Physical Structure file like Data files, Redolog files,Temp files, Controlfiles, Parameter files etc.

When we talk about the Database size, We consider the total size of the Data files, Redolog files and Temp files as their size is noticeable which constitute the Database.

Below are the Sql Query for the same.

 select
 sum(used.bytes) / 1024 / 1024 / 1024  || ' GB' Database_Size,
 sum(used.bytes) / 1024 / 1024 / 1024  - free.space / 1024 / 1024 / 1024 || ' GB' Used_space,
 free.space / 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) space
 from dba_free_space) free
 group by free.space;
 If you want to compute the tablespace size.

col "TABLESPACE_NAME" format a15
col "USED_SPACE" format 999,999,999
col "TABLESPACE_SIZE" format 999,999,999
col "USED_PERCENT" format 999,999,999
select * from dba_tablespace_usage_metrics order by used_percent desc;


No comments:

Post a Comment