SQL Server Log File (AKA LDF file) is huge - reduce size
During an insert or update to a SQL database, you may encounter an error like this:
[Microsoft][ODBC SQL Server Driver][SQL Server]The log file for database 'MyDataBase' is full. Back up the transaction log for the database to free up some log space.
If the database is set to full recovery, the LDF file can get huge. Example 27 GB.
These steps can be used to remove the LDF and replace it so that it is smaller. These steps were done using SQL Server 2005 Management Studio.
- Right click the database
- Select Properties
- Go to the Options Page
- Note what the recovery model is set to. Mine was "Full"
- Click OK
- Right click the database
- Select Tasks
- Select Back up
- Change the Backup Type to "Transaction Log"
- Select current destination backup file listed.
- Click Remove. Note – depending on your nightly backup you may have to put this back. I did not since my backups do not depend on this.
- Click Add
- Enter in a UNC path to another server to store the backup. Example: //Server1/common/MyDataBase_Log.bak
- Click OK
- Click OK to start the backup
Once the backup completed.
- Right click the database
- Click Detach
- Check the Drop Connections check box
- Check the Update Statistics checkbox
- Click OK
- Moved the bloated LDF file off the server (or delete it)
- Right click the server in Management Studio
- Selected Attach
- Click Add
- Locate the MDF
- Click OK
- Select the LDF in the bottom pane
- Click remove (a new one will get built)
- Click OK
- The LDF is auto rebuild and is small.
- Right Click the database
- Select Properties
- Go to the Options page
- Set the Recovery back to the way it was originally. I changed mine from Simple to Full.
Popular Articles
Last viewed:
- Using Stored Procedures in the Entity Framework with Scalar Return Values
- SQL Server Database Project and Database Source Control
- ASP.NET 301 Redirect for Search Engine Compliant Redirects
- Installing an SSL / TLS certificate on Windows Server 2008
- Using Windows as an FTP Client
- Clustered Index vs. Non-Clustered Index in SQL Server
Recent comments
- URL absolute path problem after URL rewriting
5 days 11 hours ago - don't work :(
1 week 1 day ago - I really loved reading your
1 week 1 day ago - PERFECT!!!
2 weeks 4 hours ago - Awsome!!
2 weeks 1 day ago - C# insert image
2 weeks 2 days ago - jkll
2 weeks 4 days ago - Thank You
2 weeks 5 days ago - Another approach
3 weeks 16 hours ago - Issue
3 weeks 1 day ago

Perfect
Thanks, I appreciate it!
reduce log file size
Thank you very much . . .
thanks
nice
nice post
perfect. you win. we win.
thank you
Logfile Reduce
Thanks this idea. I am very very thankfull to you
Rahul Ranjan(DBA)
9990402537
Reduce LDF Size
So what happens going forward? Will it grow to a massive size I again? Any way to setup an automatic something (like a maintenance plan)?
hdiaz
Really Really useful, thanks a lot
log file size
Great and usefull
Reduce LDF file size.
That was a great post!
Thanks,
Tim
LDF size reducing
Marvellous post. This was what i was looking for. Thanks a lot !!!!!