Unable to Reclaim Allocated Space After Shrinking Azure SQL Database

Dattatray Giramkar 0 Reputation points
2025-06-14T14:39:48.0966667+00:00

We are experiencing an issue with reclaiming allocated space from our Azure SQL Database (Pass Service)despite running DBCC SHRINKDATABASE. The database in question (db_name) currently shows approximately 300 GB of used space but over 1 TB of allocated space.

We have taken the following steps:

  • Verified free space using sys.database_files and FILEPROPERTY(..., 'SpaceUsed')
  • Attempted shrink using DBCC SHRINKDATABASE ([db_name]);
  • Enabled AUTO_SHRINK via ALTER DATABASE [db_name] SET AUTO_SHRINK ON;

Confirmed there are no blocking transactions during the shrink attempt

Observed the operation starts but does not reduce file size significantly

Azure portal still reports high allocated space, affecting our storage cost

Our goal is to free up approximately 600 GB of unused space and reduce the storage billing. We would like to understand:

Why the allocated space is not being released after shrink

Whether any limitations exist in Azure SQL PaaS for reclaiming space

How to reduce the max allocated storage reflected in billing

Please advise on how to proceed, and whether a manual intervention from Microsoft is needed to reset or reclaim unused space.

Thank you.

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Vijayalaxmi Kattimani 3,065 Reputation points Microsoft External Staff Moderator
    2025-06-16T04:20:35.8366667+00:00

    Hi Dattatray Giramkar

    Greetings!

    In addition to the response provided by @Erland Sommarskog, I would like to add the following information.

    As we understand that, you are facing a challenge with reclaiming space after shrinking your Azure SQL Database.

    Here are some steps you can take to address this issue:

    As suggested by @Erland Sommarskog in the first response, turn off the AUTO_SHRINK option right away. It's generally not advisable since it can lead to performance issues.

    Determine file size whether it's the data files, the log file, or both that are large. You can check the size by querying:

    SELECT file_id,
    CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint) * 8 / 1024 AS space_used_mb,
    CAST(size AS bigint) * 8 / 1024 AS space_allocated_mb,
     CAST(max_size AS bigint) * 8 / 1024 AS max_size_mb
    FROM sys.database_files
    WHERE type_desc = 'ROWS';
    

    This helps you understand the file layout and identify which file(s) need shrinking.

    Instead of DBCC SHRINKDATABASE, consider using DBCC SHRINKFILE on the specific data file that you want to reduce:

    DBCC SHRINKFILE (your_data_file_name, TRUNCATEONLY);
    

    This method is often more effective and allows targeted shrinking.

    Sometimes, long-running transactions can prevent the shrink operation from completing. You can use the following query to identify such transactions:

    SELECT * FROM sys.dm_exec_requests WHERE status = 'running';
    

    Terminating these transactions if safe to do so (caution advised) could help succeed in shrinking.

    If you run a shrink command, it can lead to fragmentation. After shrinking, you may want to conduct index maintenance (rebuild or reorganize) to ensure optimal performance:

    ALTER INDEX ALL ON your_table_name REBUILD;
    

    Be aware that even after shrinking, your database may still show high allocated space until the next billing cycle. There’s typically no immediate adjustment on the billing side until usage patterns change.

    We would like to inform you that, there are generally no specific limitations beyond those imposed by your service tier. However, the behavior might vary slightly between service tiers (like General Purpose vs. Business Critical).

    I would request you to refer the below mentioned links for more information.

    https://learn.microsoft.com/en-us/azure/azure-sql/database/file-space-manage?view=azuresql-db

    https://learn.microsoft.com/en-us/sql/relational-databases/databases/shrink-a-file?view=sql-server-ver17&source=recommendations

    https://learn.microsoft.com/en-us/sql/relational-databases/databases/shrink-a-database?view=sql-server-ver17&source=recommendations

    https://dba.stackexchange.com/questions/325901/how-to-reclaim-space-on-sql-server-azure

    I hope, This response will address your query and helped you to overcome on your challenges. If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    If you still have questions, please let us know what is needed in the comments so the question can be answered.

    Thank you for helping to improve Microsoft Q&A!


Your answer

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