This SQL, inspired by this, shows how full the tablespaces are :
SELECT tablespace_name ||
' is ' ||
TO_CHAR(ROUND(100-(free_bytes*100/total_bytes), 2)) ||
'% full.' T, total_bytes, free_bytes
FROM (SELECT a.tablespace_name, a.total_bytes, b.free_bytes
FROM (SELECT tablespace_name,
NVL(SUM(bytes), 1) AS total_bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) AS free_bytes
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
)
ORDER BY tablespace_name;
Another way of doing it is like this (courtesy of this site) :
select a.TABLESPACE_NAME,
a.BYTES bytes_used,
b.BYTES bytes_free,
b.largest,
round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used
from
(
select TABLESPACE_NAME,
sum(BYTES) BYTES
from dba_data_files
group by TABLESPACE_NAME
) a,
(
select TABLESPACE_NAME,
sum(BYTES) BYTES ,
max(BYTES) largest
from dba_free_space
group by TABLESPACE_NAME
) b
where a.TABLESPACE_NAME=b.TABLESPACE_NAME
order by ((a.BYTES-b.BYTES)/a.BYTES) desc
Copyright (c) 2024 Michel Hollands