Showing posts with label transaction log. Show all posts
Showing posts with label transaction log. Show all posts

Wednesday, 30 October 2013

Creating a Simple SQL Maintenance Plan

In this article, I will discuss the steps on how to create a simple maintenance plan in SQL that will backup both database and transaction logs.

Here are the steps to follow:
  1. Right click Maintenance Plan >> Select New Maintenance Plan.
  2. New Maintenance Plan













  3. Drag a Back up Database Task from toolbox.
  4. Back Up Database Task











  5. Double click Back up Database Task to set the properties. Set Backup type to FULL.
  6. Back Up Database Task




















  7. Add another Back Up Database Task and rename it to Back Up Transaction Log Task.
  8. Back Up Database Task




















  9. Double click Backup Transaction Log Task to set properties. Set Backup Type to Transaction Log.
  10. Back Up Transaction Log Task





















In the steps mentioned above, we did not shrink the .ldf file but rather we simply backup the transaction log after full database back up. The effect of backing up the transaction log tells SQL Server that it is safe to reuse the space consumed by the transaction log. So if the size of transaction log at that time is 300 MB, SQL will reuse the 300 MB space to record new transactions instead of consuming more hard disk space.

As a finishing touch you can add a File Maintenance Task to delete the backup files in server. Note: If it is production I hope you back up your database somewhere before you delete the backup in your server.

Maintenance Cleanup Task



Tuesday, 1 October 2013

Shrink Database Logs

Shrinking the transaction log file is a process of reducing the size of the transaction log. This process is important because if the transaction log file is left unchecked it can grow until it consumes the hard disk space of your server.

Listed below are the steps on how to truncate or shrink database log files (LDF) in your Development or Local Servers. In these steps we will set the database into a Simple Recovery Model which automatically reclaims log space. 
  1. Right click database >> Options >> Set Recovery Model to Simple >> OK
  2. Right click database >> Tasks >> Shrink >> Files
  3. Select File type = Log >> OK
  4. Set back the Recovery Model to Full

For more information about recovery model refer to http://msdn.microsoft.com/en-us/library/ms189275.aspx