KB · Oracle Database · Script

Tablespace usage against autoextend max size, not just allocated space

Oracle Database · Script · Verified on Oracle 11.2 and 23ai · Updated 2026-12-03

Errors this answers

  • ORA-01653: unable to extend table
  • ORA-01654: unable to extend index

Most tablespace reports divide used space by allocated space. With autoextend on, that number is close to 100% most of the time and means nothing. What matters is used space against the size the files are allowed to grow to.

ScriptAnswers
tabsp.sqlEvery tablespace: allocated, used, free, and % used of the autoextend maximum, fullest last
dbfai.sqlFor one tablespace (or all): usage per datafile, and each file's current size, max size, unallocated headroom and growth increment

Usage

SQL> @tabsp.sql
SQL> @dbfai.sql
Enter Tablespace Name (Enter=ALL): USERS

Run as a DBA: autoextend limits come from sys.filext$.

tabsp.sqlMIT · Download ·
-- tabsp.sql: tablespace usage against the autoextend maximum, fullest last
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/tablespace-usage-with-autoextend/
--
-- Usage: @tabsp.sql
--
-- Reads sys.ts$, sys.file$ and sys.filext$ for autoextend limits: run as a DBA.


set pages 60
set lines 132
set trims on
set tab off

column  pct_used 	format 999.9		heading "%|Used" 
column  pct_max_used 	format 999.9		heading "%|Used" 
column  ts_name    	format a35		heading "Tablespace Name" 
column  Mbytes   	format 999,999,999  heading "MBytes" 
column  used    	format 999,999,999  heading "Used MB" 
column  free    	format 999,999,999  heading "Free MB" 
column  largest    	format 999,999,999  heading "Largest" 
column  cur_size    	format 999,999,999  heading "Curr MB" 
column  max_size    	format 999,999,999  heading "Max MB" 
column  unallocated    	format 999,999,999  heading "Unalloc MB" 
break   on report 
compute sum of mbytes on report 
compute sum of free on report 
compute sum of used on report 

select	nvl(c.tablespace_name,nvl(a.tablespace_name,'UNKNOWN'))	ts_name
,	mbytes_alloc						mbytes
,	mbytes_alloc-nvl(mbytes_free,0)				used
,	nvl(mbytes_free,0)					free
,	((mbytes_alloc-nvl(mbytes_free,0))/mbytes_alloc)*100	pct_used
--,	nvl(largest,0)						largest
,       c.max_size    max_size
,       c.unallocated unallocated
,	((mbytes_alloc-nvl(mbytes_free,0))/c.max_size)*100	pct_max_used
from	(select	sum(bytes)/1024/1024		Mbytes_free
	,		max(bytes)/1024/1024	largest
	,		tablespace_name
	from 		dba_free_space
	group by	tablespace_name)			a
,       (   select tabsp_name tablespace_name, sum(cur_size)/1024/1024 mbytes_alloc, sum(max_size)/1024/1024 max_size, sum(unallocated)/1024/1024 unallocated
            from (
                    select  /*+ ORDERED */
                            tn.name                tabsp_name
                    ,       ddf.file_name          file_name
                    ,       ddf.bytes              cur_size
                    ,       decode(fex.maxextend,
                                    NULL,ddf.bytes
                                        ,fex.maxextend*tn.blocksize) max_size
                    ,       ((nvl(fex.maxextend,0)*tn.blocksize) -
                            decode(fex.maxextend,NULL,0,ddf.bytes))   unallocated
                    ,       nvl(fex.inc,0)*tn.blocksize               inc_by
                    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#
                )
            group by tabsp_name ) c
where	a.tablespace_name(+) = c.tablespace_name
order by pct_max_used;

curl -O https://hashjoin.com/kb/oracle/tablespace-usage-with-autoextend/tabsp.sql

dbfai.sqlMIT · Download ·
-- 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

curl -O https://hashjoin.com/kb/oracle/tablespace-usage-with-autoextend/dbfai.sql

Reading the output

In tabsp.sql, the first % Used column is against allocated space and the second against the autoextend maximum. Alert on the second. A tablespace at 99% / 40% is fine; one at 80% / 97% is about to fail with ORA-01653 or ORA-01654.

When it's close, dbfai.sql shows which files still have headroom. If none do, add a datafile or raise MAXSIZE on one; also check that the filesystem or ASM disk group really has that space free.

Gotchas

What it reads

dba_free_space dba_data_files sys.ts$ sys.file$ sys.filext$

Tired of fixing the same thing twice?

HASHJOIN turns the checks and fixes your on-call runs by hand into tooling that gives the same answer every time. Fixed scope, and you own all of the code.