表領域の使用率を見やすく表示するSQL

表領域使用率を見やすく表示するSQL
表領域の情報、表領域名、サイズ、使用量、使用率、を見やすく表示するSQLについて書きます。
SQLはこうです。
ttitle -
center 'Database Freespace Summary' skip 2
comp sum of nfrags totsiz avasiz on report
break on report
set pages 999
col tsname format a16 justify c heading 'Tablespace'
col nfrags format 999,990 justify c heading 'Free|Frags'
col mxfrag format 999,999 justify c heading 'Largest|Frag (MB)'
col totsiz format 9,999,999 justify c heading 'Total|(MB)'
col avasiz format 999,999 justify c heading 'Available|(MB)'
col pctusd format 990 justify c heading 'Pct|Used'
select total.TABLESPACE_NAME tsname,
D nfrags,
C/1024/1024 mxfrag,
A/1024/1024 totsiz,
B/1024/1024 avasiz,
(1-nvl(B,0)/A)*100 pctusd
from
(select sum(bytes) A,
tablespace_name
from dba_data_files
group by tablespace_name) TOTAL,
(select sum(bytes) B,
max(bytes) C,
count(bytes) D,
tablespace_name
from dba_free_space
group by tablespace_name) FREE
where
total.TABLESPACE_NAME=free.TABLESPACE_NAME(+);
実行するとこのような結果を得られます。見やすくて、わかりやすいですね。
Database Freespace Summary
Free Largest Total Available Pct
Tablespace Frags Frag (MB) (MB) (MB) Used
---------------- -------- --------- ---------- --------- ----
SYSTEM 3 7 770 8 99
USERS 1 4 5 4 26
UNDOTBS2 8 3,968 25,600 25,248 1
SYSAUX 46 55 1,100 80 93
UNDOTBS1 8 3,968 25,600 25,086 2
TS_ZAIKO 4 99 400 396 1
-------- ---------- ---------
sum 135 59,775 57,037
6行が選択されました。
タグ:oracle, tablespace, 使用率

