SQL Server Tips

SQL Server Shrink: Best Practices

Updated
2 min read
Written by
Mark 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. You can learn more here, in this excellent article by Paul Randal.

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.

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

Article by
Mark Varnas
Founder | CEO | SQL Veteran
Hey, I'm Mark, one of the guys behind Red9. I make a living performance tuning SQL Servers and making them more stable.

Leave a Comment

Managed SQL Server services, consulting, and emergency support from expert DBAs to improve performance, predictability, and cost.

Get started with Red9 today.

Contact us

Discover More

SQL Server Health Check SQL Server Migrations & Upgrades SQL Server Performance Tuning SQL Server Security SQL Server Tips

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 Staats 5 stars
Rich Staats
Cloud Engineer
MetalToad

Always willing to go an extra mile

Working with Red9 DBAs has been a pleasure. They are great team players and have an expert knowledge of SQL Server database administration. And are always willing to go the extra mile to get the project done.
5 stars
Evelyn A.
Sr. Database Administrator

Boosts server health and efficiency for enhanced customer satisfaction

Since adding Red9 to the reporting and DataWarehousing team, Red9 has done a good job coming up to speed on our environments and helping ensure we continue to meet our customer's needs. Red9 has taken ownership of our servers ensuring they remain healthy by monitoring and tuning inefficient queries.
5 stars
Andrew F.
Datawarehousing Manager
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