views:

255

answers:

3

I have just turned on page compression on a table (SQL 2008 Ent) using the following command:

ALTER TABLE [dbo].[Table1] REBUILD PARTITION = ALL
WITH 
(DATA_COMPRESSION = PAGE
)

The hard drive now contains 50GB less space than before. I'm guessing that I need to run a command to reclaim the space. Anyone know it?

A: 

Here is a great article I found using google. It might have some answers for you. http://www.devx.com/SQL_Server/Article/41171/0/page/2

Daniel A. White
It's a good article! But doesn't answer my question unfortunately.
Mr. Flibble
+1  A: 

Have you checked using the table size using sp_spaceused?

Disk space used does not equal space used by data. The compression will have affected log file size (all has to be logged) and required some free working space (like the rule of thumb that index rebuild requires free space = 1.2 times largest table space).

Another option is that you need to rebuild the clustered index because it's fragmented. This compacts data and is the only way to reclaim space for text columns.

Also, read Linchi Shea's articles on data compression

gbn
+1  A: 

I feel embarrassed even asking this question, but is it something that could be fixed by shrink the database in question? As it compressed the pages, perhaps it left the space free all throughout the file, and the data files just need to be condensed and shrunk to reclaim the space...

If it created a new, compressed copy of the table and then removed the old one from the file, but didn't shrink the file internally, this might also explain your sudden lack of space on the drive as well.

If this is the case, then a simple "DBCC SHRINKDATABASE('my_database')" should do the trick. NOTE: This may take a long time, and lock the database during that time so as to prevent access, so schedule it wisely.

rwmnau
That's probably the command I need to use. Unfortunately I'm getting error:"Msg 0, Level 11, State 0, Line 0A severe error occurred on the current command. The results, if any, should be discarded."when I run it. Ugh.
Mr. Flibble
Ouch - that's pretty ugly. Is there enough free space on the disk to accommodate a second copy of the entire file? If there is, then perhaps you can create a second file in the current group and migrate everything to that, then remove the currently large file from the group. I'm happy to provide a script for that.Are there are any other events in the SQL or Application logs at the same time that might shed some more light? I appreciate, but I'd love to earn it by getting your database shrunk!
rwmnau

related questions