テーブルスペースの使用率を確認する


テーブルスペースのサイズ、空き領域はdba_data_files、dba_free_spaceで確認できる。
それらを利用した使用率を確認するSQLは以下の通り。

select
   tablespace_name,
   to_char(nvl(total_bytes / 1024,0),'999,999,999') as "全サイズ(KB)",
   to_char(nvl((total_bytes - free_total_bytes) / 1024,0),'999,999,999') as "使用サイズ(KB)",
   to_char(nvl(free_total_bytes/1024,0),'999,999,999') as "空きサイズ(KB)",
   round(nvl((total_bytes - free_total_bytes) / total_bytes * 100,100),2) as "使用率(%)"
from
   ( select
       tablespace_name,
       sum(bytes) total_bytes
     from
       dba_data_files
     group by
       tablespace_name
   )
   left join 
   ( select
       tablespace_name as free_tablespace_name,
       sum(bytes) free_total_bytes
     from
       dba_free_space
     group by tablespace_name
   )
 on
   tablespace_name = free_tablespace_name
 order by 1


また、テーブルスペースの定義の情報はdba_tablespacesで確認できる。

SELECT tablespace_name, 
        initial_extent "INITIAL", 
        next_extent "NEXT",
         min_extents, 
         max_extents, 
         DEF_TAB_COMPRESSION as 自動表領域拡張
FROM dba_tablespaces


動作確認環境:Oracle 10g