查看oracle表空间使用情况

查看oracle表空间的实用情况

查看表空间实用情况1

SELECT D.TABLESPACE_NAME                                       表空间名称,
       D.STATUS                                                表空间状态,
       TO_CHAR(NVL(A.BYTES / 1024 / 1024, 0), '99,999,990.90') 大小,
       TO_CHAR(NVL(A.BYTES - NVL(F.BYTES, 0), 0) / 1024 / 1024,'99999999.99')                                                已使用,
       TO_CHAR(NVL((A.BYTES - NVL(F.BYTES, 0)) / A.BYTES * 100, 0),'990.00') || '%' 使用百分比
FROM SYS.DBA_TABLESPACES D,
     (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES
      FROM DBA_DATA_FILES
      GROUP BY TABLESPACE_NAME) A,
     (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES
      FROM DBA_FREE_SPACE
      GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = A.TABLESPACE_NAME(+)
  AND D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
  AND NOT (D.EXTENT_MANAGEMENT LIKE 'LOCAL' AND D.CONTENTS LIKE 'TEMPORARY')
UNION ALL
SELECT D.TABLESPACE_NAME                                         表空间名称,
       D.STATUS                                                  表空间状态,
       TO_CHAR(NVL(A.BYTES / 1024 / 1024, 0), '99,999,990.90')   大小,
       TO_CHAR(NVL(T.BYTES, 0) / 1024 / 1024, '99999999.99')     已使用,
       TO_CHAR(NVL(T.BYTES / A.BYTES * 100, 0), '990.00') || '%' 使用百分比
FROM SYS.DBA_TABLESPACES D,
     (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES
      FROM DBA_TEMP_FILES
      GROUP BY TABLESPACE_NAME) A,
     (SELECT TABLESPACE_NAME, SUM(BYTES_CACHED) BYTES
      FROM V$TEMP_EXTENT_POOL
      GROUP BY TABLESPACE_NAME) T
WHERE D.TABLESPACE_NAME = A.TABLESPACE_NAME(+)
  AND D.TABLESPACE_NAME = T.TABLESPACE_NAME(+)
  AND D.EXTENT_MANAGEMENT LIKE 'LOCAL'
  AND D.CONTENTS LIKE 'TEMPORARY';

查看表空间实用情况2

select dbf.tablespace_name                                     表空间名称,
       dbf.totalspace                                          总量,
       dbf.totalblocks as                                      总块数,
       dfs.freespace                                           剩余总量,
       dfs.freeblocks                                          剩余块数,
       round((dfs.freespace / dbf.totalspace) * 100, 2) || '%' 空闲比例
from (select t.tablespace_name,
             sum(t.bytes) / 1024 / 1024 totalspace,
             sum(t.blocks)              totalblocks
      from dba_data_files t
      group by t.tablespace_name) dbf,
     (select tt.tablespace_name,
             sum(tt.bytes) / 1024 / 1024 freespace,
             sum(tt.blocks)              freeblocks
      from dba_free_space tt
      group by tt.tablespace_name) dfs
where trim(dbf.tablespace_name) = trim(dfs.tablespace_name);
上一篇:如何查看数据库的大小,和空间使用情况(oracle)


下一篇:查找oracle数据库表相关信息语句