Friday, November 18, 2011

Queries to check tablespace size etc (Including TEMP)

Queries to check tablespace size etc (Including TEMP)

1. This SQL will not take TEMP into account:

select
  b.file_id "File #",
  substr(b.tablespace_name,1,15) "Tablespace Name",
  b.bytes / 1024 "# Kbytes",
  ((b.bytes / 1024) - sum(nvl((a.bytes / 1024),0))) "# used",
  sum(nvl(a.bytes,0) / 1024) "# free",
  trunc((sum(nvl(a.bytes,0))/(b.bytes))*100,3) "%free"
from
  sys.dba_free_space a,
  sys.dba_data_files b
 where
 a.file_id(+) = b.file_id
 group by
 b.tablespace_name,
 b.file_id,
b.bytes
order by
b.tablespace_name;

2. For inclusion of TEMP use this:


SELECT /* + RULE */  df.tablespace_name "Tablespace",
       df.bytes / (1024 * 1024) "Size (MB)",
       SUM(fs.bytes) / (1024 * 1024) "Free (MB)",
       Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free",
       Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used"
  FROM dba_free_space fs,
       (SELECT tablespace_name,SUM(bytes) bytes
          FROM dba_data_files
         GROUP BY tablespace_name) df
 WHERE fs.tablespace_name (+)  = df.tablespace_name
 GROUP BY df.tablespace_name,df.bytes
UNION ALL
SELECT /* + RULE */ df.tablespace_name tspace,
       fs.bytes / (1024 * 1024),
       SUM(df.bytes_free) / (1024 * 1024),
       Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1),
       Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes)
  FROM dba_temp_files fs,
       (SELECT tablespace_name,bytes_free,bytes_used
          FROM v$temp_space_header
         GROUP BY tablespace_name,bytes_free,bytes_used) df
 WHERE fs.tablespace_name (+)  = df.tablespace_name
 GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
 ORDER BY 4 DESC;




No comments:

Post a Comment