-- dbfai.sql: datafile usage and autoextend headroom for one tablespace or all -- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/) -- https://hashjoin.com/kb/oracle/tablespace-usage-with-autoextend/ -- -- Usage: @dbfai.sql then enter a tablespace name, or press Enter for all accept ts_name char prompt "Enter Tablespace Name (Enter=ALL): " ttitle skip center "*** DATAFILE USAGE ***" clear computes clear breaks set pages 1000 set lines 163 set trims on col tablespace_name format a27 heading "Tablespace Name" col file_name format a59 heading "File Name" col total_size_KB format 999999999999999 heading "Size KB" col free_space_KB format 999999999999999 heading "Free KB" col total_size format 999,999,999.00 heading "Size MB" col free_space format 999,999,999.00 heading "Free MB" col pct_used format 999.00 heading "%|Used" clear breaks select /*+ ORDERED */ df.tablespace_name , df.file_name , df.bytes/1024 total_size_KB , nvl(fr.bytes/1024,0) free_space_KB , df.bytes/1024/1024 total_size , nvl(fr.bytes/1024/1024,0) free_space , ((df.bytes-nvl(fr.bytes,0))/df.bytes)*100 pct_used from (select sum(bytes) bytes , file_id from dba_free_space group by file_id) fr , dba_data_files df where df.file_id = fr.file_id(+) and DECODE(UPPER('&&ts_name'),NULL,'x',df.tablespace_name) like DECODE(UPPER('&&ts_name'),NULL,'x',UPPER('&&ts_name')) order by 1, df.file_id; ttitle skip center "*** DATAFILE AUTOEXTEND ***" clear computes clear breaks break on tabsp_name skip 1 col file_name format a59 heading "Data File Name" col tabsp_name format a27 heading "Tablespace Name" col max_size format 999,999,999.99 heading "Max|Size MB" col inc_by format 999,999,999.99 heading "Inc|By MB" col unallocated format 999,999,999.99 heading "Unalloc|MB" col cur_size format 999,999,999.99 heading "Current|Size MB" compute sum of max_size cur_size unallocated on tabsp_name select /*+ ORDERED */ tn.name tabsp_name , ddf.file_name file_name , ddf.bytes/1024/1024 cur_size , decode(fex.maxextend, NULL,ddf.bytes/1024/1024 ,fex.maxextend*tn.blocksize/1024/1024) max_size , nvl(fex.maxextend,0)*tn.blocksize/1024/1024 - decode(fex.maxextend,NULL,0,ddf.bytes/1024/1024) unallocated , nvl(fex.inc,0)*tn.blocksize/1024/1024 inc_by --from sys.v_$dbfile fn from dba_data_files ddf , sys.ts$ tn , sys.filext$ fex , sys.file$ ft where ddf.file_id = ft.file# and ddf.file_id = fex.file#(+) and tn.ts# = ft.ts# and DECODE(UPPER('&&ts_name'),NULL,'x',ddf.tablespace_name) like DECODE(UPPER('&&ts_name'),NULL,'x',UPPER('&&ts_name')) order by tn.name, ddf.file_id; undefine ts_name