Oracle SQL to show used/free space by tablespace name

Here is the SQL to show used/free space by tablespace name. You may need SELECT_CATALOG_ROLE privilege to run the SQL.


--Tablespace: Show used/free space by tablespace name
SELECT (select name from v$database) "Instance",
to_char(sysdate, 'dd-MON-yyyy hh24:mi:ss') time_stamp,
Total.name "Tablespace Name",
nvl(Free_space, 0) Free_GB,
nvl(total_space-Free_space, 0) Used_GB,
total_space Total_GB,
nvl(round(Free_space*100/total_space,2), 0) "%Free"
FROM
(select tablespace_name, round(sum(bytes/1024/1024/1024),3) Free_Space
from sys.dba_free_space
group by tablespace_name
) Free,
(select b.name,  round(sum(bytes/1024/1024/1024),3) TOTAL_SPACE
from sys.v_$datafile a, sys.v_$tablespace B
where a.ts# = b.ts#
group by b.name
) Total
WHERE Free.Tablespace_name(+) = Total.name
--and Total.name in ('OLAPD')
ORDER BY Total.name;

Leave a comment