Problem solve Get help with specific problems with your technologies, process and projects.

Space usage: Predicting the future by means of geometric series

Predict space usage with this query.

In our daily practice of managing space usage, we most often tend to focus on our largest objects when trying to forecast the amount of space we need to allocate for the future growth. Yet unpleasant surprises can often come from the side of smaller objects that are about to request additional extents (or a number of them). To answer the following questions...

  1. Is there enough space in my tablespaces to allocate the next N extents related to the tables that have less than M % of free space left?
  2. What percentage and amount of space will I be left with in case such allocations occur?

...all you need to do is run this query. It has been tested on Oracle 8.1.7, Standard Edition.

The total size of the next N extents is calculated as the sum of the geometric series, starting with the NEXT_EXTENT as the first element and having the multiplier of (PCT_INCREASE+1). The calculation takes into account both TABLE & INDEX extents for tables in question.

You will be asked to provide the following values:

  • the number of extents whose size you want to estimate
  • the percenatage of free space left within the tables of interest

Column "Currently_FREE_MB" will report the amount of free space currently available within a tablespace. Column "Next_Extents_MB" will tell you what will be the total size of your next extents. Columns "Free_PCT_Left" & "Free_MB_Left" will let you know how much space you will be left with, in percentages and Megabytes, respectively.

Any negative figures, or figures close to zero for the column FreePCTLeft should raise the alarm. The cases of PCT_INCREASE being equal to zero are also being taken into account. The assumption has been made tables are analyzed, thus the data dictionary columns referenced contain non-NULL values. You could easily build a function based on this query to focus on specific table names, number of extents and free space percentages only, passing these values as parameters.

SET termout on echo off feedback off termout on verify
off
VARIABLE vNextExtNo NUMBER 
VARIABLE vFreePCT NUMBER 

ACCEPT vNextExtNo PROMPT 'Enter the Number of Extents: '
ACCEPT vFreePCT  PROMPT  'Enter the Table Free Percent value: '

SELECT 
a.tablespace_name, b.currently_free_mb, a.next_extents_mb,
100-ROUND (a.next_extents_mb / b.currently_free_mb,2)* 100 free_pct_left,
ROUND (b.currently_free_mb - a.next_extents_mb, 2) free_mb_left
FROM (SELECT tablespace_name,
  ROUND (SUM (DECODE (pct_increase, 0, &&vnextextno * next_extent, 
(next_extent*(POWER(1+pct_increase/100,&&vnextextno)-1)/(pct_increase / 100))))/ 1048576,2) next_extents_mb
 FROM dba_segments
 WHERE (owner, segment_name) IN
  (SELECT owner, table_name
                 FROM dba_tables
   WHERE ROUND (100 * empty_blocks / (empty_blocks+blocks),2) < &&vfreepct + 1
   UNION
                 SELECT owner, index_name
                        FROM dba_indexes
                  WHERE (table_owner, table_name) IN
                         (SELECT owner, table_name
                                 FROM dba_tables
                                 WHERE ROUND (100*empty_blocks/empty_blocks+blocks),2) < &&vfreepct+ 1))
 GROUP BY tablespace_name) a,
 (SELECT tablespace_name,
  ROUND (SUM (bytes) / 1048576, 2) currently_free_mb
  FROM dba_free_space
        GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name;

UNDEFINE vNextExtNo
UNDEFINE vFreePCT

 

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free Oracle tips and scripts.
  • Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: Oracle tips, tutorials, and scripts from around the Web.


 

Dig Deeper on Oracle database backup and recovery

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close