Independent senior database engineering · Pittsburgh, PAsbajwa@bajwaconsulting.com

Tablespace growth forecaster

Which tablespace fills up first, and when? Paste the output of one of the queries below. See the growth per day, the date each tablespace will be full and a days-until-full chart. Your data stays in your browser.

1 Paste your tablespace history

One line per tablespace per day: date, tablespace, used MB, max MB. Commas, tabs, pipes or spaces all work, and header lines are ignored. Use one of the queries below to produce it.

Queries that produce the history

Option A: from AWR (up to the AWR retention, usually 8 days or more). Needs the Diagnostics Pack. Run in a non-CDB, or in a PDB that has PDB-level AWR snapshots (AWR_PDB_AUTOFLUSH_ENABLED); otherwise use option B.

SET HEADING OFF FEEDBACK OFF PAGESIZE 0 LINESIZE 200 TRIMSPOOL ON
SELECT TO_CHAR(TRUNC(TO_DATE(u.rtime, 'MM/DD/YYYY HH24:MI:SS')), 'YYYY-MM-DD') || ',' ||
       t.name || ',' ||
       ROUND(MAX(u.tablespace_usedsize * ts.block_size) / 1048576) || ',' ||
       ROUND(MAX(u.tablespace_maxsize  * ts.block_size) / 1048576)
FROM   dba_hist_tbspc_space_usage u
JOIN   v$tablespace t      ON t.ts# = u.tablespace_id
JOIN   dba_tablespaces ts  ON ts.tablespace_name = t.name
WHERE  TO_DATE(u.rtime, 'MM/DD/YYYY HH24:MI:SS') > SYSDATE - 90
AND    ts.contents = 'PERMANENT'
GROUP  BY TRUNC(TO_DATE(u.rtime, 'MM/DD/YYYY HH24:MI:SS')), t.name
ORDER  BY 1;

Option B: no extra licence. Run this once a day (for example from cron or DBMS_SCHEDULER) and append the output to a file. After a few weeks, paste the whole file here.

SET HEADING OFF FEEDBACK OFF PAGESIZE 0 LINESIZE 200 TRIMSPOOL ON
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD') || ',' || d.tablespace_name || ',' ||
       ROUND((d.bytes - NVL(f.bytes, 0)) / 1048576) || ',' || ROUND(d.maxbytes / 1048576)
FROM  (SELECT tablespace_name, SUM(bytes) bytes,
              SUM(GREATEST(bytes, DECODE(autoextensible, 'YES', maxbytes, bytes))) maxbytes
       FROM dba_data_files GROUP BY tablespace_name) d
LEFT JOIN (SELECT tablespace_name, SUM(bytes) bytes FROM dba_free_space
           GROUP BY tablespace_name) f ON f.tablespace_name = d.tablespace_name
ORDER BY 1;

For a one-off look at current usage, see tablespace_usage.sql in the DBA scripts library.