clear columns
column tablespace format a30
column total_mb format 999,999,999.99
column used_mb format 999,999,999,999.99
column free_mb format 999,999,999.99
column pct_used format 999.99
column graph format a22 heading "GRAPH (X=5%)"
column status format a7
compute sum of total_mb on report
compute sum of used_mb on report
compute sum of free_mb on report
break on report
set lines 200 pages 100
SELECT
total.ts TABLESPACE,
DECODE(total.mb, NULL, 'OFFLINE', dbat.status) status,
total.mb total_mb,
NVL(total.mb - free.mb, total.mb) used_mb,
NVL(free.mb, 0) free_mb,
DECODE(total.mb, NULL, 0, NVL(ROUND((total.mb - free.mb)/(total.mb)*100, 2), 100)) pct_used,
CASE
WHEN (total.mb IS NULL) THEN '['||RPAD(LPAD('OFFLINE', 13, '-'), 20, '-')||']'
ELSE '['|| DECODE(free.mb, NULL, 'XXXXXXXXXXXXXXXXXXXX', NVL(RPAD(LPAD('X', TRUNC((100-ROUND((free.mb)/(total.mb) * 100, 2))/5), 'X'), 20, '-'), '--------------------'))||']'
END AS GRAPH
FROM
(SELECT tablespace_name ts, SUM(bytes)/1024/1024 mb FROM dba_data_files GROUP BY tablespace_name) total,
(SELECT tablespace_name ts, SUM(bytes)/1024/1024 mb FROM dba_free_space GROUP BY tablespace_name) FREE,
dba_tablespaces dbat
WHERE total.ts=free.ts(+)
AND total.ts=dbat.tablespace_name
UNION ALL
SELECT
sh.tablespace_name,
'TEMP',
SUM(sh.bytes_used+sh.bytes_free)/1024/1024 total_mb,
SUM(sh.bytes_used)/1024/1024 used_mb,
SUM(sh.bytes_free)/1024/1024 free_mb,
ROUND(SUM(sh.bytes_used)/SUM(sh.bytes_used+sh.bytes_free)*100, 2) pct_used,
'['||DECODE(SUM(sh.bytes_free), 0, 'XXXXXXXXXXXXXXXXXXXX', NVL(RPAD(LPAD('X',(TRUNC(ROUND((SUM(sh.bytes_used)/SUM(sh.bytes_used+sh.bytes_free))*100, 2)/5)),'X'), 20, '-'), '--------------------'))||']'
FROM v$temp_space_header sh
GROUP BY tablespace_name
ORDER BY 6 DESC
Output:
TABLESPACE STATUS TOTAL_MB USED_MB FREE_MB PCT_USED GRAPH
---------------------- --------- ---------- ---------- ---------- ---------- ----------------------
ONE_4M_T ONLINE 132 132 0 100 [XXXXXXXXXXXXXXXXXXXX]
TWO_128K_I ONLINE 5 1 4 20 [XXXX----------------]
THREE_256M_T ONLINE 10 1,5 8,5 15 [XXX-----------------]
FOUR_256M_T ONLINE 10 1 9 10 [XX------------------]
TEMP_02 TEMP 102400 2 102398 0 [--------------------]