Query to find tablespace usage

Use the below query to find table space usage 

set pages 10000
set linesize 250
col tablespace_name format a15 heading 'TableSpace|Name'
col AvailSpace format 9999990.90 heading 'Total Size|(in Mb)'
col FreeSpace format 9999990.90 heading 'FreeSpace |(in Mb)'
col UsedSpace format 9999990.90 heading 'UsedSpace |(in Mb)'
SELECT
 dts.tablespace_name,
 (ddf.bytes / 1024 / 1024) "AvailSpace",
 (ddf.bytes - (dfs.bytes))/1024/1024 "UsedSpace",
 (dfs.bytes / 1024 / 1024) "FreeSpace",
 TO_CHAR(((ddf.bytes - (dfs.bytes)) / ddf.bytes * 100),'990.00') "Used %"
 FROM
 sys.dba_tablespaces dts,
 (select tablespace_name, sum(bytes) bytes
  from dba_data_files group by tablespace_name) ddf,
   (select tablespace_name, sum(bytes) bytes
    from dba_free_space group by tablespace_name) dfs
    WHERE
     dts.tablespace_name = ddf.tablespace_name(+)
    AND dts.tablespace_name = dfs.tablespace_name(+)
    AND NOT (dts.extent_management like 'LOCAL'
    AND dts.contents like 'TEMPORARY')
    UNION ALL
    SELECT dts.tablespace_name,
     (dtf.bytes / 1024 / 1024) "AvailSpace",
     (t.bytes)/1024/1024 "UsedSpace",
     (dtf.bytes - (t.bytes))/1024/1024 "FreeSpace",
     TO_CHAR((t.bytes / dtf.bytes * 100), '990.00') "Used %"
    FROM
     sys.dba_tablespaces dts,
     (select tablespace_name, sum(bytes) bytes
     from dba_temp_files group by tablespace_name) dtf,
      (select tablespace_name, sum(bytes_used) bytes
      from v$temp_space_header group by tablespace_name) t
 WHERE
 dts.tablespace_name = dtf.tablespace_name(+)
 AND dts.tablespace_name = t.tablespace_name(+)
 AND dts.extent_management like 'LOCAL'
 AND dts.contents like 'TEMPORARY'
/

Comments

Popular posts from this blog

Oracle Cloud Infrastructure(OCI) - Part2

Script to display the SQL text for a specific SQL_ID

How to Change Your EnterpriseOne Environment Color