Search notes:

Oracle: Calculate free space in tablespaces

The following query calculates the used and available space in tablespaces:
select
   tablespace_name,
   round(total_space_gb, 1)  total_gb,
   round(free_space_gb , 1)  free_gb,
   to_char(100 * free_space_gb / total_space_gb, '990.0' ) || ' %' free_pct
from
(
    select
      ts.tablespace_name,
      ts.total_space_gb,
      ts.total_space_gb - df.used_space_gb  free_space_gb
   from
      (
        select
           tablespace_name,
           sum(bytes) / 1024/1024/1024 as total_space_gb
        from
           dba_data_files
        group by
           tablespace_name
      )                                                     ts left join
      (
        select
           tablespace_name,
           sum(bytes) / 1024/1024/1024 as used_space_gb
        from
           dba_segments
        group by
           tablespace_name
      )                                                      df on df.tablespace_name = ts.tablespace_name
)
-- where
--     tablespace_name = 'TS_XYZ'
;

TODO

Should the statement query from dba_free_space rather than from dba_segments?

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1741045565, '3.146.255.206', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/architecture/database/logical-structures/tablespace/free-space(70): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78