How to make your SQL Server database grow exponentially with linear data

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Pieter Myburgh (pieterm_at_korbitec.com)
Date: 04/23/04


Date: Fri, 23 Apr 2004 14:48:25 +0200

We have this database that we use to collect 1000's of rows of data a day.
Particularly in one table we collect about 1000 pieces of data a day in the
form of very small blobs (64k or so). Our database has been growing
steadily from Nov 2003 with an initial size of 7gb to about 25gb on 10 April
2004. Not bad, seeing the amount of data we collect. Then from 10 April to
today (23 April) it grew to 65gb in about 2 weeks. What's going on? Did
our input data increase exponentially? No, according to our logs data have
been arriving in a linear fashion. Maybe there's about 40gb of unused space
in the database? No, after we rebuild the indexes (using dbcc updateusage)
SQL Server reports no free space. Not possible you say?

Well, turns out the problem are with the blob fields. Because we want to
minimize the time it takes to search through the table, we wrote a service
that takes 2 rows, adds the blobs together, then updates the one row with
the resulting blob and deletes the other row. The service in other words
doubles up the blobs. The resulting blobs are also doubled up and so forth.
This in itself should not be a problem because theoretically the new row
should take up the same space (or even slightly less) than the original 2
rows together. Wrong! What happens is when a blob gets bigger than 64k,
SQL Server does not store the blob data with the row anymore, but moves it
to a separate location. Now when you double up a blob and try to update the
row SQL Server realizes it can't store the blob in the same space as the
previous one, so it allocates new space for it. So even though you aren't
adding any new data to the database, the database file actually grows
exponentially! Now some smaller blobs will eventually take up the old space
of a bigger blob, but they are much lower on the exponential curve than the
bigger blobs, so in total your database file grows near exponential with
linear data. This can be quite a problem when your blob size gets to about
50mb or so, and is the cause of our database growing so quickly in such a
short time.

Also, what worsens the problem is that it seems that SQL Server does not
take these deallocated blob space into account when it calculates "unused"
space in the database. Now if we deleted both rows in a double-up operation
and inserted a new row we probably would have been able to shrink the
database periodically. But there does not seem to be anything we can do to
reclaim deallocated blob space Our aim is to stop the blobs growing when
they reach a certain size and archive them off. Has anybody experienced the
same problem, or are there any suggestions as to how we can reclaim (or
avoid) this "unused" space?

Thanks,

Pieter



Relevant Pages

  • Re: SQLite speed tests BLOB vs flat-file for those interested
    ... My main concern was speed of reading rows from database. ... No indexes in any database file. ... This format may be very fast to read BLOB, but every update may be pain. ...
    (alt.comp.lang.borland-delphi)
  • RE: How to make your SQL Server database grow exponentially with linear data
    ... > We have this database that we use to collect 1000's of rows of data a day. ... > SQL Server reports no free space. ... turns out the problem are with the blob fields. ... > and inserted a new row we probably would have been able to shrink the ...
    (microsoft.public.sqlserver.server)
  • Re: How to make your SQL Server database grow exponentially with linear data
    ... Turns out it's a bug in SQL Server, ... database, which means there was only about 17gb of actual data in the ... separate data file, so when it gets out of control again we can just move ... turns out the problem are with the blob fields. ...
    (microsoft.public.sqlserver.server)
  • Re: manipulating blobs in sqlplus
    ... SQL Server). ... There is also no size limit on the blob field ... site outside of the database and have a script load them in. ... 15 returning theBlob into l_blob; ...
    (comp.databases.oracle.server)
  • Re: Blobs and SQL Server
    ... Older versions of SQL Server required the blob be loaded in chunks, ... There is a cpu and disk IO hit while inserting the blob. ... Director of Text Mining and Database Strategy ... If a large file is inserted, then it will require many small chunks. ...
    (microsoft.public.sqlserver.fulltext)