dataiotech Labs
Scripts Library/oracle/#63
Script #63
oracle
Storageread-onlyMin Version: 11g

Oracle Tablespace Usage Including Autoextend

Calculates tablespace usage against the real maximum, honoring autoextend limits. Catches space errors like ORA-01653 before they happen.

#tablespace#capacity#autoextend
oracle · sql
SELECT df.tablespace_name,
       ROUND(df.max_mb, 0)  AS max_mb,
       ROUND(df.alloc_mb, 0) AS allocated_mb,
       ROUND(df.alloc_mb - NVL(fs.free_mb, 0), 0) AS used_mb,
       ROUND(100 * (df.alloc_mb - NVL(fs.free_mb, 0)) / df.max_mb, 1) AS used_pct_of_max
FROM (SELECT tablespace_name,
             SUM(bytes) / 1048576 AS alloc_mb,
             SUM(CASE WHEN autoextensible = 'YES' THEN GREATEST(maxbytes, bytes) ELSE bytes END) / 1048576 AS max_mb
      FROM dba_data_files GROUP BY tablespace_name) df
LEFT JOIN (SELECT tablespace_name, SUM(bytes) / 1048576 AS free_mb
           FROM dba_free_space GROUP BY tablespace_name) fs
       ON fs.tablespace_name = df.tablespace_name
ORDER BY used_pct_of_max DESC;
Operational Notes & Remediation Guidance

Tablespaces approaching 90% without autoextend enabled require immediate datafile addition or storage expansion.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 11g).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.

Engineering Triad: Related Runbooks & Incident Response

Which production incidents and emergency drills execute this script as a diagnosis step?

Runbook Library (63)
Related Alerts & Metrics
M38Oracle Tablespace Usage (vs. Max Size)Oracle