views:

53

answers:

2

Hello,

I have a table in an Oracle db that gets a couple of million new rows every month. Each row has a column which states the date when it was created.

I'd like to run a query that gets the disk space growth over the last 6 months. In other words, the result would be a table with two columns where each row would have the month's name and disk space used during that month.

Thanks,

+2  A: 

This article reports a method of getting the table growth: http://www.dba-oracle.com/t_table_growth_reports.htm

column "Percent of Total Disk Usage" justify right format 999.99
column "Space Used (MB)" justify right format 9,999,999.99
column "Total Object Size (MB)" justify right format 9,999,999.99
set linesize 150
set pages 80
set feedback off

select * from (select to_char(end_interval_time, 'MM/DD/YY') mydate, sum(space_used_delta) / 1024 / 1024 "Space used (MB)", avg(c.bytes) / 1024 / 1024 "Total Object Size (MB)", 
round(sum(space_used_delta) / sum(c.bytes) * 100, 2) "Percent of Total Disk Usage"
from 
   dba_hist_snapshot sn, 
   dba_hist_seg_stat a, 
   dba_objects b, 
   dba_segments c
where begin_interval_time > trunc(sysdate) - &days_back
and sn.snap_id = a.snap_id
and b.object_id = a.obj#
and b.owner = c.owner
and b.object_name = c.segment_name
and c.segment_name = '&segment_name'
group by to_char(end_interval_time, 'MM/YY'))
order by to_date(mydate, 'MM/YY');
WoLpH
+2  A: 

DBA_TABLES (or the equivalent) gives an AVG_ROW_LEN, so you could simply multiply that by the number of rows created per month.

The caveats to that are, it assumes that the row length of new rows is similar to that of existing rows. If you've got a bunch of historical data that were 'small' (eg 50 bytes) but new rows are larger (150 bytes), then the estimates will be too low.

Also, how do updates figure into things ? If a row starts at 50 bytes and grows to 150 two months later, how do you account for those 100 bytes ?

Finally, tables don't grow for each row insert. Every so often the allocated space will fill up and it will go and allocate another chunk. Depending on the table settings, that next chunk may be, for example, 50% of the existing table size. So you might not physically grow for three months and then have a massive jump, then not grow for another six months.

Gary
Use DBA_SEGMENTS instead of DBA_TABLES. It will tell you exactly how much space an object is using on disk, and it's not dependent on estimates or statistics.
jonearles
Remember, a table can be made up of partitions which DBA_TABLES won't account for. As jonearles suggests, DBA_SEGMENTS and account for the partitions, also, if you want to include binary object columns (BLOB, CLOB) DBA_LOBS also because LOBs not stored inline are in their own segment.
Stellios
As far as I know AVG_ROW_LEN is an optimizer statistic, and not a real measure. I mean, with appropiate permissions, you can overwrite its value. See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#i997763
gpeche