SQL Server DBCC SHRINKFILE is not reducing database file size

Shishir Kumar 0 Reputation points
2026-11-30T09:30:57.4266667+00:00

We are facing an issue with shrinking a large SQL Server database file.

The affected database xyz and the data file is Data.

The current file size is approximately 1.16 TB, out of which approximately 664 GB is occupied by data. There is approximately 527 GB of unused space available within the file.

We are trying to reclaim this unused space and reduce the physical database file size.

However, despite multiple attempts, the shrink operation is not reducing the file size as expected.

Troubleshooting performed:

  1. Attempted all three available shrink options through SQL Server Management Studio.

Executed DBCC SHRINKFILE using different target sizes.

Monitored the shrink operation to check its progress.

Verified the database file size and available unused space.

Repeated the operation through both SQL commands and the SSMS interface.

The issue persists, and the physical database file size remains unchanged.

We require Microsoft's technical guidance on the following:

What could prevent SQL Server from moving allocated data pages towards the beginning of the database file?

How can we identify allocated pages or database structures preventing the shrink operation?

Are there any known SQL Server Database Engine issues that could cause DBCC SHRINKFILE to stop progressing?

Are there alternative Microsoft recommended methods to reclaim unused space without compromising database integrity?

What diagnostic queries or troubleshooting steps should we perform to identify the root cause?

This database occupies a significant amount of storage capacity. The inability to reclaim unused space is creating storage management concerns.

We request guidance from Microsoft on identifying the underlying issue and implementing a safe resolution with minimal production impact.

We can provide SQL Server configuration details, diagnostic query results, execution logs and screenshots for further investigation.

SQL Server
SQL Server

A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.


1 answer

Sort by: Most helpful
  1. AI answer

    2026-11-30T09:32:25.9733333+00:00

    The next step is to identify whether Data is waiting on a transaction or contains an unmovable allocation near its physical end, because total free space alone does not guarantee that SQL Server can truncate the end of the file.

    1. Establish the attainable size

    Run this in xyz; it is diagnostic and does not initiate another shrink:

    USE xyz;
    GO
    SELECT
        file_id,
        name,
        type_desc,
        size / 128.0 AS CurrentSizeMB,
        FILEPROPERTY(name, 'SpaceUsed') / 128.0 AS UsedSpaceMB,
        (size - FILEPROPERTY(name, 'SpaceUsed')) / 128.0 AS FreeSpaceMB,
        growth,
        is_percent_growth
    FROM sys.database_files
    WHERE name = N'Data';
    

    DBCC SHRINKFILE moves allocated pages from the area being removed into free space below the target. TRUNCATEONLY does not move pages and can release space only after the last allocated extent; NOTRUNCATE moves pages but deliberately leaves the physical file unchanged.^1^

    Do not target exactly the reported 664 GB. SQL Server cannot shrink below the storage required for allocated pages, and operational headroom is needed to avoid immediate autogrowth.

    2. Determine whether the operation is blocked

    While shrink is running, locate its session and inspect its current wait:

    SELECT
        r.session_id,
        r.status,
        r.command,
        r.wait_type,
        r.wait_time,
        r.wait_resource,
        r.blocking_session_id,
        r.percent_complete,
        r.total_elapsed_time
    FROM sys.dm_exec_requests AS r
    WHERE r.database_id = DB_ID(N'xyz')
       OR r.command LIKE N'DbccFilesCompact%';
    

    Compare wait_type, wait_time, and wait_resource across several samples. A changing or resetting wait indicates progress; a persistent blocking session identifies the next investigation point.^2^

    Also search the SQL Server error log for message 5203. That message means DBCC SHRINKFILE is waiting for a row-versioning/snapshot transaction. Identify such transactions with:

    USE xyz;
    GO
    SELECT
        session_id,
        transaction_sequence_num,
        first_snapshot_sequence_num,
        elapsed_time_seconds
    FROM sys.dm_tran_active_snapshot_database_transactions
    ORDER BY elapsed_time_seconds DESC;
    

    The supported choices are to let the blocking transaction finish, end that transaction after assessing application impact, or cancel shrink; completed shrink work is retained.^1^

    IAM-page locking can also stop progress: shrink needs an Sch-M lock while queries can hold Sch-S locks. On SQL Server 2022 or later, WAIT_AT_LOW_PRIORITY reduces interference with normal queries, but it can time out after one minute. Do not use ABORT_AFTER_WAIT = BLOCKERS without change approval because it terminates blocking user transactions and requires ALTER ANY CONNECTION or KILL DATABASE CONNECTION permission.^3^

    3. Identify the object owning a reported page

    If error 49516 or another shrink message reports a file ID and page ID, map that page to its object. On SQL Server 2019 or later:

    USE xyz;
    GO
    SELECT
        OBJECT_SCHEMA_NAME(pg.object_id) AS schema_name,
        OBJECT_NAME(pg.object_id) AS object_name,
        i.name AS index_name,
        p.partition_number
    FROM sys.dm_db_page_info(DB_ID(), <file_id>, <page_id>, DEFAULT) AS pg
    JOIN sys.indexes AS i
      ON i.object_id = pg.object_id AND i.index_id = pg.index_id
    JOIN sys.partitions AS p
      ON p.partition_id = pg.partition_id;
    

    sys.dm_db_page_info returns the owning object, index, and partition from the page header and is supported beginning with SQL Server 2019.^4^

    For allocation consistency—not merely placement—run during a suitable maintenance window:

    DBCC CHECKALLOC (N'xyz') WITH NO_INFOMSGS, ALL_ERRORMSGS;
    

    If errors are reported, restore from a known-good backup rather than immediately using repair; repair can delete pages and data.^5^

    4. Check version-specific immovable structures

    Confirm the exact SQL Server version and build, then inspect whether the end-of-file object uses columnstore and LOB columns:

    SELECT @@VERSION;
    
    SELECT s.name, o.name, i.name, i.type_desc
    FROM sys.indexes AS i
    JOIN sys.objects AS o ON o.object_id = i.object_id
    JOIN sys.schemas AS s ON s.schema_id = o.schema_id
    WHERE i.type_desc LIKE N'%COLUMNSTORE%';
    

    Applicable known issues include:

    • Before SQL Server 2025, LOB pages in compressed columnstore segments cannot be moved by shrink.^1^
    • SQL Server 2014 nonclustered columnstore pages had a shrink defect fixed in SQL Server 2014 CU2.^6^
    • Specific SQL Server 2008–2014 builds had a LOB-space reclamation defect; the documented remedies are the applicable cumulative update, rebuilding the data in a new table, or migrating it through another file.^7^

    5. Safer reclamation alternatives

    If Data is not the only file in its filegroup—or another sufficiently large file can be added—the documented alternative is DBCC SHRINKFILE (Data, EMPTYFILE), which migrates data to other files in the same filegroup. After validation and backup, the empty file can be removed. Ensure the destination files and storage have sufficient capacity first.^1^

    For a 1.16-TB file, Microsoft also provides the ShrinkDriver PowerShell sample, which makes large-file shrink observable, resumable, and retryable. Shrinking can increase index fragmentation, so validate fragmentation and query performance afterward; avoid making shrink or AUTO_SHRINK routine maintenance.^8^


    References

    1. DBCC SHRINKFILE (Transact-SQL)
    2. Understand and resolve SQL Server blocking problems
    3. DBCC SHRINKDATABASE (Transact-SQL)
    4. sys.dm_db_page_info (Transact-SQL)
    5. DBCC CHECKALLOC (Transact-SQL)
    6. KB2967198 – KORREKTUR: DBCC SHRINKDATABASE oder DBCC SHRINKFILE können keine Seiten verschieben, die zum nicht gruppierten Columnstore-Index gehören - SQL Server | Microsoft Support
    7. KB2967240 - FIX: Cannot reclaim unused space by using shrink operation in the table that contains a LOB column in SQL Server - SQL Server | Microsoft Support
    8. Shrink a file
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.