8

我需要知道Oracle 中的真实表空间大小。我有一些表空间,我需要知道它现在使用了多少空间以及有多少可用空间(可能还有可用空间的百分比)。我在网上发现了一些 sql,但它们都显示了基于水印的大小......这不是现在分配的真正空间,但据我所知,这是曾经达到的最高值......所以我真正需要知道如果我有足够的空间来存储不断写入的数据,并且我必须知道在删除其中一些数据之前可以存储多少。

谢谢

4

3 回答 3

19

尝试这个:

-- 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);
于 2010-02-05T12:30:20.937 回答
5

如果您想了解数据文件的大小,包括那些可以自动扩展的文件,请尝试:

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
于 2010-10-12T13:35:15.507 回答
0

希望这会对您有所帮助,

 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;
于 2012-11-20T21:17:07.940 回答