SQL Server Tips

SQL Server Shrink: Best Practices

Updated October 29, 20252 min read

Written byMark Varnas

What is database file shrinking in SQL Server?

Shrinking data files recovers space by moving and returning pages of data to the file system.

Why should you not shrink your data files?

Regularly shrinking databases (data files, to be more specific) is terrible.

It drains resources and creates severe index fragmentation. If you want to understand just how bad it can get - and what to do instead - this article breaks it all down.

Make sure auto shrink is disabled

Best practices recommend disabling it, so ensure it is turned off.

  1. Using SSMS, expand Databases.
  2. Right-click on the database name and select Properties.
  3. Set the Auto Shrink property on the Options page to False, and click OK.
Figure 1 - Auto Shrink SQL Server option
Figure 1 - Auto Shrink SQL Server option

Also, you can change the AUTO_SHRINK database option to OFF using T-SQL, as shown below (make sure to replace yourdb to your database name):

ALTER DATABASE yourdb

SET AUTO_SHRINK OFF

Note:SQL Server auto shrink feature is disabled by default on SQL Server instance databases.

Sometimes you do have to shrink data files

Use DBCC SHRINKFILE only in exceptional circumstances.

For instance, if you had deleted a large amount of data that was not needed soon, or if you had dropped many large, unused indexes.

In those cases, or in both:

  1. Identify low-use server times that you can run the shrink.
  2. Monitor your Agent Jobs and watch SQL Server for blocking if you don’t have an outage window.
  3. Use DBCC SHRINKFILE and set a specific, targeted size for the file you’re shrinking.
  4. When shrink is finished, use ALTER INDEX REORGANIZE to reduce index fragmentation.
  5. Finally, if necessary, shrink the log file, explicitly grow LDF to keep the VLF count low.

More information

Discover More

Discover what clients are saying about Red9

Red9 has incredible expertise both in SQL migration and performance tuning.

The biggest benefit has been performance gains and tuning associated with migrating to AWS and a newer version of SQL Server with Always On clustering. Red9 was integral to this process. The deep knowledge of MSSQL and combined experience of Red9 have been a huge asset during a difficult migration. Red9 found inefficient indexes and performance bottlenecks that improved latency by over 400%.

Rich StaatsRich StaatsCloud EngineerMetalToad
See more testimonials

Check Red9's SQL Server Services

SQL Server Consulting

Perfect for one-time projects like SQL migrations or upgrades, and short-term fixes such as performance issues or SQL remediation.

Discover More ➜

SQL Server Managed Services

Continuous SQL support, proactive monitoring, and expert DBA help with one predictable monthly fee.

Discover More ➜

Emergency SQL Support

Take the stress out of emergencies with immediate access to a SQL Server Sr. DBA 24x7x365

Discover More ➜

Explore All Services ➜