Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Shrinking Database or File not Reclaiming unused space


Shrinking Database or File not Reclaiming unused space

Author
Message
dr.blowfin
dr.blowfin
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 244
Hello,
First time poster, long time lurker. I thought this was an interesting enough question to ask.

Pretty often we bring our clients databases (we sell software which backs onto an SQL server database) back in house to cut into test environments. Something we do to these databases is drop all the BLOB data so we're not dealing with several hundred GB of essentially useless data. We just don't need it for testing and dev work. I've carried out the following steps and have tried to shrink the data file and database without getting any space reclaimed. I'm wondering why this is happening and would like to figure out a way to reclaim the space without having to backup and restore the database. Any advice or thoughts would be welcome, this strikes me as a bit of an oddity and I'm sure there's a good reason for the behavior buried under the hood somewhere.

-Switched to simple recovery mode (to avoid log bloat, maybe pointless when dropping the column?)
-Dropped stats on blob columns
-Dropped Blob Columns
-Rebuilt indexes on the tables containing the blobs
-Recreated the blob columns
-Switched back to full recovery mode
-Attempted file shrink on data file (no change in size)
-Attempted database shrink (no change in size)
Perry Whittle
Perry Whittle
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11635 Visits: 16844
Interesting one this, there is a known issue around the removal of LOB data in sql server. Dropped LOB data is not removed immediately, there is a ghost process that runs in the background and removes the ghosted records.

Truncating the table as far as i remember will clear the table but i couldn't say for sure when just dropping the column.

Once you drop the column have you tried querying the system catalogs to see what allocated, used and reserved space sql server thinks the table\index object has?

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
dr.blowfin
dr.blowfin
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 244
Perry Whittle (4/16/2013)
Once you drop the column have you tried querying the system catalogs to see what allocated, used and reserved space sql server thinks the table\index object has?


Not directly after the drop, is it worth repeating the process and noting the stats? It's an overnight restore but I'm not strapped for time.

Here are some figures after I've recreated the column, clearly without the LOB data:

rows           reserved   data           index_size   unused
1770892 107544 KB 86392 KB 21048 KB 104 KB



Stats were reporting 0 ghost records present in the table and that the index rebuild didn't have any traction while the column was still dropped, after recreating the column and rebuilding again the fragmentation got cleared up. The below is prior to recreating the column:

database_id   object_id   index_id   partition_number   index_type_desc           alloc_unit_type_desc   index_depth   index_level   avg_fragmentation_in_percent   fragment_count   avg_fragment_size_in_pages   page_count
5 287340088 1 1 CLUSTERED INDEX IN_ROW_DATA 3 0 95.9996295953329 10389 1.03946481855809 10799
5 287340088 2 1 NONCLUSTERED INDEX IN_ROW_DATA 3 0 99.9604743083004 2530 1 2530


Perry Whittle
Perry Whittle
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11635 Visits: 16844
check results of the following query both before and after the drop


SELECT OBJECT_NAME(i.object_id) AS TableName
, ISNULL(i.name, 'HEAP') AS IndexName
, i.index_id as IndexID
, i.type_desc AS IndexType
, p.partition_number AS PartitionNo
, p.rows AS NumRows
, au.type_desc AS InType
, au.total_pages AS NumPages
, au.total_pages * 8 AS TotKBs
, au.used_pages * 8 AS UsedKBs
, au.data_pages * 8 AS DataKBs
FROM sys.indexes i INNER JOIN sys.partitions p
ON i.object_id = p.object_id AND i.index_id = p.index_id
INNER JOIN sys.allocation_units au ON
CASE
WHEN au.type IN (1,3) THEN p.hobt_id
WHEN au.type = 2 THEN p.partition_id
END = au.container_id
WHERE OBJECT_NAME(i.object_id) = 'yourtable'



-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
dr.blowfin
dr.blowfin
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 244
Before:

IndexName   IndexID   IndexType   PartitionNo   NumRows   InType   NumPages   TotKBs   UsedKBs   DataKBs
Pk__Key 1 CLUSTERED 1 1770892 LOB_DATA 84581293 676650344 676590280 0
Pk__Key 1 CLUSTERED 1 1770892 IN_ROW_DATA 19946 159568 159448 157520
Pk__Key 1 CLUSTERED 1 1770892 ROW_OVERFLOW_DATA 0 0 0 0
DK_ 2 NONCLUSTERED 1 1770892 IN_ROW_DATA 5834 46672 46552 44912



And after:

Pk__Key   1   CLUSTERED   1   1770892   LOB_DATA   84581293   676650344   676590280   0
Pk__Key 1 CLUSTERED 1 1770892 IN_ROW_DATA 19946 159568 159448 157520
Pk__Key 1 CLUSTERED 1 1770892 ROW_OVERFLOW_DATA 0 0 0 0
DK_ 2 NONCLUSTERED 1 1770892 IN_ROW_DATA 5834 46672 46552 44912



And after the index rebuild:
Pk__Key   1   CLUSTERED   1   1770892   IN_ROW_DATA   10915   87320   87272   86392
DK_ 2 NONCLUSTERED 1 1770892 IN_ROW_DATA 2546 20368 20312 20240


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search