Sql Server LDF file taking too large space

1. Why is the log file taking this much space (30gb)?

It was because the Autogrowth / Maxsize was set 200,000 MB

2. how can I free up the space?

As described Here i used the following command and the file is now less than 200mb

ALTER DATABASE myDatabaseName
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE (myDatabaseName_log, 1)
GO
ALTER DATABASE myDatabaseName_log
SET RECOVERY FULL

I have also set Autogrowh/Maxsize in the database properties to 1000 as Limited (See the image below).

<code>Database Propertis => Files</code> in SSMS

The link describes more, so I recommend referring it for detailed description and other options.
Thanks @hadi for the link.


1.Why is the log file taking this much space (30gb)?

  • Or because of your recovery not SIMPLE and ldf grown eventually to such size
  • Or because there was a large one-time DML operation
  • Or because of other reasons, as noted by @sepupic in another answer

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 a code snippet of @sepupic


Some members still give and advice to physicaly remove LDF files.

I highly suggest to not do this. Remarkable related post of 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. etc.

Tags:

Sql Server