For any High volume db operated websites that contains millions of data, that also in binary formats too, it’s common that the transaction log files (.ldf files) will grow at an incredible rate without our notice and at some stage makes our hard disk fully occupied. So taking a backup of this database and restoring it somewhere else is not possible if the hard disk in target server has not enough space to accomplish the db. In one of our real-time scenarios we have got upto 50 GB of log file size in production server. We cant ever guarantee the client that how much hard disk space he needs to keep in his server.
So the most feasible solution is always keep that high volume LDF files in your backup and assign a new LDF file to the db. The following 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.

By doing like this i have reduced my 50GB ldf file to 504KB ldf file …WoooW….

Leave a Reply