True tablespace size in oracle

半腔热情 提交于 2019-12-03 13:40:00

Try this:

-- Available space, by tablespace

SELECT * FROM
  (SELECT tablespace_name FROM dba_tablespaces)
LEFT OUTER JOIN
  (SELECT tablespace_name, SUM(bytes) AS total_bytes
     FROM dba_data_files
     GROUP BY tablespace_name)
  USING (tablespace_name)
LEFT OUTER JOIN
  (SELECT tablespace_name, sum(bytes) AS used_bytes
     from dba_segments
     GROUP BY tablespace_name)
  USING (tablespace_name)
LEFT OUTER JOIN
  (SELECT tablespace_name, SUM(bytes) AS free_bytes
     FROM dba_free_space
     GROUP BY tablespace_name)
  USING (tablespace_name);

If you want to get an idea of data file size including those files that can auto extend then try:

SELECT DISTINCT a.tablespace_name,
            sum(a.bytes)/1024/1024 CurMb,
            sum(decode(b.maxextend, null, a.bytes/1024/1024, b.maxextend*(SELECT value FROM v$parameter WHERE name='db_block_size')/1024/1024)) MaxMb,
            round(100*(sum(a.bytes)/1024/1024 - round(c.free/1024/1024))/(sum(decode(b.maxextend, null, a.bytes/1024/1024, b.maxextend*(SELECT value FROM v$parameter WHERE name='db_block_size')/1024/1024)))) UPercent,
            (sum(a.bytes)/1024/1024 - round(c.free/1024/1024)) TotalUsed,
            (sum(decode(b.maxextend, null, a.bytes/1024/1024, b.maxextend*(SELECT value FROM v$parameter WHERE name='db_block_size')/1024/1024)) - (sum(a.bytes)/1024/1024 - round(c.Free/1024/1024))) TotalFree 
FROM dba_data_files a,
   sys.filext$ b,
   (SELECT d.tablespace_name , sum(nvl(c.bytes,0)) free
     FROM dba_tablespaces d,dba_free_space c
     WHERE d.tablespace_name = c.tablespace_name(+) 
     GROUP BY d.tablespace_name) c
WHERE a.file_id = b.file#(+)
    AND a.tablespace_name = c.tablespace_name  
GROUP BY a.tablespace_name,
       c.free/1024

Hopefully, this would assist you,

 SELECT a.tablespace_name, a.file_name, a.bytes allocated_bytes,b.free_bytes FROM dba_data_files a,
(SELECT file_id, SUM(bytes) free_bytes FROM dba_free_space b GROUP BY file_id) b WHERE a.file_id=b.file_id
ORDER BY a.tablespace_name;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!