Azure SQL DBCC ShrinkDatabase takes too long
When database allocated space is in hundreds of gigabytes or higher, shrink might require a significant time to complete, often measured in hours, or days for multi-terabyte databases. Some suggestions to speed up the process:
- Rebuild indexes with low page density.
- It is recommended to first execute shrink for each data file with the
TRUNCATEONLY
parameter. This way, if there is any allocated but unused space at the end of the file, it is removed quickly and without any data movement. - If the database has multiple data files, you can speed up the process by shrinking multiple data files in parallel. You do this by opening multiple database sessions, and using
DBCC SHRINKFILE
on each session with a differentfile_id
value
For more information, read this this documentation.
Read more here: Source link