How do I prevent log files from growing exponentially?

  • Page Owner: Not Set
  • Last Reviewed: 2022-01-14

I was having performance issues on my computer and noticed the storage space on my computer was about maxed out. After using a tool to identify what files were taking up the most space, I found a 700+ GB log file. However, I couldn't delete the log file because it "was being used by another process". How do you delete log files and prevent this from happening in the first place?


Answer

For local development we don't care about point-in-time recovery, so we can set recovery to simple. This will make sure SQL Server re-uses portions of the log file instead of having it grow exponentially.

ALTER DATABASE <db_name> SET RECOVERY SIMPLE;

After running the above SQL on my database I was able to delete the offending log file. I found a lot of this in this post: https://stackoverflow.com/questions/56628/how-do-you-clear-the-sql-server-transaction-log

You can also set the max file size for your log file (this has to be done before the size gets out of hand). Right-click db in SQL Server Management Studio and select properties. The setting is in the Files page under the Autogrowth / Maxsize table column.