Why is my database log file taking to high space? It's taking up almost 30GB of my HDD. Even after deleting 1,000,000 records, it's not freeing up any space.
- Why is the log file taking this much space (30gb)?
It was because the Autogrowth / Maxsize was set to 200,000 MB.
- How can I free up the space?
As described here I used the following command and the file is now less than 200 MB.
ALTER DATABASE myDatabaseName
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE (myDatabaseName_log, 1)
GO
ALTER DATABASE myDatabaseName_log
SET RECOVERY FULL
I have also set Autogrowth/Maxsize in the database properties to 1000 in the Limited option (See the image below).

The link describes more, so I recommend referring it for detailed description and other options.
1.Why is the log file taking this much space (30gb)?
2.how can I free up the space?
IF recovery is other than SIMPLE:
Firstly backup transaction log file
Perform a shrink, like DBCC SHRINKFILE(2,256)
IF recovery is SIMPLE:
Just shrink it to desired size, like DBCC SHRINKFILE(2,256)
If the database log still did not reduce to a target size, then the exact reason to be checked, by using the code snippet from sepupic's answer
Some members still give and advice to physically remove LDF files. I highly suggest that you not do this. From a related post by Aaron Bertrand:
Some things you don't want to do:
Detach the database, delete the log file, and re-attach. I can't emphasize how dangerous this can be. Your database may not come back up, it may come up as suspect, you may have to revert to a backup (if you have one), etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With