Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

How to Shrink SQL Server Database Log File

5.00/5 (3 votes)
2 Nov 2019CPOL2 min read 2.5K  
How to shrink SQL Server database log file

Image 1

Shrink SQL Server Log Files

I have been asked this question a lot of times that my log file size is increased and I want to shrink it but don't know how to perform this.

So I decided to make a post for this task so it can help people.

Let's start with the process.

  1. Log in to the SQL Server using SSMS (SQL Server Management Studio) with administrator credentials.
  2. Select the database whose log file size is increased.
  3. Take the full backup of that database so that in case of any issue during shrink operation, we will have the original backup and it can be restored. Make sure the recovery model should be "Full" as displayed in the image below:

    Image 2

  4. Right click the database and click properties, and select the "Files" option from the left menu of Database Properties dialog box. You can see the log file size here as displayed in the image below:

    Image 3

  5. Now you need to change the recovery option to Simple instead of Full. So click the "Options" tab in Database Properties dialog box. Now choose the Recovery model to "Simple".

    Image 4

  6. Now click OK and close this dialog box. Right click the database and select Tasks > Shrink > Files menu.
  7. It will open the Shrink File dialog box. Select the "Log" from File Type drop down and select the "Release unused space" option as displayed in the image below:

    Image 5

  8. Now click the OK button and it will start the Shrink process and after some time, it will shrink the log file size and you will notice the log file size would be minimized.
  9. Now you can revert back the recovery model to "Full" as it was earlier. To do this, follow the step number 5 and select option "Full" and hit OK button.

Hope this will help you.

Be happy and stay optimized.

Thanks for reading!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)