1. 程式人生 > >三、查看Oracle表空間使用情況

三、查看Oracle表空間使用情況

space sel sed 空閑 extends tables nbsp ext bold

1、查詢表空間的總容量

select a.TABLESPACE_NAME, sum(a.BYTES) / 1024 / 1024 as MB
  from sys.dba_data_files a
 group by a.TABLESPACE_NAME

2、查詢表空間的空閑容量

select b.TABLESPACE_NAME,
       count(1) as extends,
       sum(b.BYTES) / 1024 / 1024 as MB,
       sum(b.BLOCKS) as blocks
  from sys.dba_free_space b
 group by b.TABLESPACE_NAME

3、查詢表空間的使用情況

select total.TABLESPACE_NAME,
       round(total.MB, 2) as TOTAL_MB,
       round(total.MB - free.MB, 2) as USED_MB,
       ROUND((1 - free.MB / total.MB) * 100, 2) || % as USED_PCT,
       ROUND(free.MB, 2) as FREE_mb
  from (select a.TABLESPACE_NAME, sum(a.BYTES) / 1024 / 1024 as MB
          
from sys.dba_data_files a group by a.TABLESPACE_NAME) total, (select b.TABLESPACE_NAME, count(1) as extends, sum(b.BYTES) / 1024 / 1024 as MB, sum(b.BLOCKS) as blocks from sys.dba_free_space b group by b.TABLESPACE_NAME) free
where total.TABLESPACE_NAME = free.TABLESPACE_NAME

三、查看Oracle表空間使用情況