1

Problem: I am working on a SQL Server 2019 database where I deleted a large amount of user data (~500 GB). After deletion, I attempted to shrink the data file using:

DBCC SHRINKFILE (N'web_Data', TARGET_SIZE_MB);

However, the shrink process stopped at 76% and could not proceed further.

Analysis:

Using sys.dm_db_database_page_allocations and sys.allocation_units, I found that:

  • LOB data and system objects (e.g., sysobjvalues, syscerts, sysasymkeys) are allocated toward the end of the file.

  • Since these allocations are not movable, the shrink operation cannot release the remaining space.

Question:

How can I perform a shrink operation that reclaims only the movable free space, without getting stuck on unmovable LOB and system data?

What I Tried:

DBCC SHRINKFILE with a target size

  • DBCC SHRINKFILE with TRUNCATEONLY

Clarifications:

  • I understand that shrinking can cause fragmentation. I’m not asking whether I should shrink, I’m asking how to reclaim only the free space that is actually reclaimable without getting blocked.

  • Rebuilding the database is not part of this question—I’m focusing on whether SQL Server allows partial shrink in this scenario.

Environment:

  • SQL Server Version: 2019

  • Database Size Before Deletion: ~1 TB

  • Deleted Data: ~500 GB from a single large table

  • File: Single data file in PRIMARY filegroup

Goal:

  • Reclaim as much space as possible using DBCC SHRINKFILE, even if system LOB data cannot be moved.

1 Answer 1

0

Of course, you can specify some higher value for the DBCC SHRINKFILE, which would technically lead to "partial shrink", but the issue with the LOB files is that they are being referenced from the rows - but there is no reference in the LOB data back to row they belong to.

Which means, that when the SQL Server wants to move LOB data, it needs to do a lot of scanning to make sure it updates all pointers towards that data. And even if you make smaller, partial shrink, the amount of data that needs to be read is not necessarily going to decrease proportionately.

In theory, the shrink operation should finish one day. In practice, you might be better of just leaving the database as it is.

2
  • Thank you for the explanation about LOB data and shrink behavior. I am trying to shrink database to reduce AWS RDS cost. Can you please suggest any other best approach to reduce the size of database? Commented Jul 21 at 13:18
  • Maybe try reorganizing the tables with lob compaction first? In theory this could cause the lob pages to move to better location. Commented Jul 22 at 9:37

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.