title: How to calculate available space in a Teradata database
body: <p>I want to report on various statistics on a specific Teradata database, particularly "free space".  Should table skew be included in the calculation?  For example, someone suggested the following query:</p>
  
  <pre><code>SELECT databasename
       , SUM(maxperm)/1024/1024/1024 (DECIMAL(10,2))     AS space_allocated
       , SUM(currentperm)/1024/1024/1024 (DECIMAL(10,2)) AS space_Used
       , (MAX(currentperm)*COUNT(*)-SUM(currentperm))
          /1024/1024/1024 (DECIMAL(10, 2)) AS skew_Size
  
       , (space_used + skew_size) AS total_space_used
  
       , (MIN(maxperm-currentperm)/1024/1024/1024) * COUNT(*) (DECIMAL(10,2)) 
          AS free_Space
  
       ,  CAST(total_space_used AS DECIMAL(10,2)) * 100 
        / CAST(space_allocated AS DECIMAL(10,2)) AS pct_used
  
  FROM   DBC.diskspace
  WHERE  databasename = 'MyDatabase'
     AND maxperm &gt; 0
  GROUP   BY 1;
  </code></pre>
  
  <p>I'm particularly curious about the calculation of <code>total_space_used</code> and <code>pct_used</code>.  Is it "proper" to account for skewed tables like this? </p>