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://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!