Know How to Shrink Log File in SQL Server Database?

  • Written By  

  • Updated on March 15th, 2022

If your system is filled with too many log files, unable to shrink log file in SQL Server. You can not delete these files either because they are useful. So, How can you maintain the efficiency of your computer without deleting these log files? The answer is the Shrink log file in SQL server database.

shrink log file in sql server

Whenever you modify the SQL Server database, it creates a log file. These files contain records of every logging process. It is a very important file for data recovery in the SQL server database. However, the log files are not filled in completely. They have some free space.

Compressing fills up this free space in each file with available data and creates room for new information. Also, shrunken log files can be used to recover the lost data. It is extremely helpful in saving useful information. Therefore, it is the SQL server shrink log file best practice.

Reason to Shrink Log File in SQL Server

Are you confused about truncating the transaction log? Think about why you are performing this action. There are some reasons to shrink the transaction log.

Shrinking log files are necessary to create room for new log files. Every modification in the data files creates log files. Therefore, the number of these files is increasing rapidly. Hence, shrinking such files is a suitable method to cope with this rapid growth.

You need to shrink log file in SQL server to create their backup. It is very essential to secure important data. The transaction log contains the information of the process. So, it is designed to restore the whole data of a database system. Therefore, you should reduce transaction log size SQL server and make its backup.

How to Shrink Database Log File Automatically in SQL Server

A shrink operation creates free usable space within the transaction log. It does not delete any file. This operation only relocates files. So, it will be helpful after performing a large number of transaction activities that create more log files.

The transaction log can only be shrunken if there is some available space in the log files. It means you can shrink files to a certain limit. After that, it will not be possible to shrink files. The steps to shrink log file in SQL server are as follow:

  • Right-click on the database and select the Tasks option. 
  • Click on the shrink option and choose the Files option.
  • A new wizard will be opened. On this page, change the file type to Log.
  • Select the log files you want to shrink.
  • Now you can choose from three options:
    • Release unused space
    • Reorganize pages before releasing unused space
    • Empty file by migrating the data to other files in the same filegroup.

Alternatively, you can shrink the log files using the DBCC SHRINKFILE T-SQL statement. The DBCC commands allow you to perform several operations.

USE [“filename’’]

Drawbacks of Shrinking the Log Files

Apart from benefits, It has limitations too. Some of them are mentioned below:

  • The log files have free space within. If you fill this space, you are interfering with the log files functioning. It can result in severe outcomes. It is more likely that the log files could corrupt and restoration of data will not be possible.
  • When you shrink the file, the data can scatter to any location. It results in index fragmentation and could lead to file corruption. In such cases, the SQL server shrink log file not working. Also, at the time of restoration, the data will not be properly indexed.

The shrinking process has various negative consequences. However, it is necessary to perform this process because the growth rate of log files is tremendous. It helps in maintaining a regular space in the system.

So, what is the safe way to shrink log file in SQL server and avoid their corruption?

Shrink Log File with SQL Log Recovery Software

SQL Log Recovery Software is a tool to repair corrupted log files. It is very simple to use. This software works for both LDF and MDF files. SQL log recovery tool is suitable for all versions of SQL server and windows. So, you can download it into your system. It has a date filter that helps you to recover files for a particular period.


Log files are created with every transaction in the database. Therefore, these files cover a large space. Shrinking these files is a suitable option to minimize this covered space. I have mentioned some methods to shrink log file in SQL Server. This operation will free up space. However, this process has limitations too. It leads to file corruption and data loss. SQL Log Recovery Software is a tool to repair the corrupted log files and restore the data completely.


Question: Should I shrink SQL log file?
Answer: You must shrink a physical log file to reduce its physical size. You can use this when you know that a transaction log file contains unused space

Question: Can we shrink tempdb log file in SQL Server?
Answer: After adding more files to tempdb, you can shrink them after restarting SQL Server as a service. When SQL Server starts, all tempdb files are created. However, these files are empty and can be removed. Use the REMOVE FILE option of the ALTER DATABASE command to remove additional files from tempdb.

About The Author:

Pallavi is a content writer in the field of data recovery and email migration. She has a passion for creating engaging and thought-provoking content. With several years of experience in the field, she has developed a deep understanding of various writing styles and formats,

Related Post

© Copyrights 2017-2024 Database File Recovery. All Rights Reserved.