join the MSSQLTips community

Today's Site Sponsor


 

Find performance issues related to Analysis Services memory limits.
 


Managing SQL Server 2000 Transaction Log Growth
Written By: Jeremy Kadlec -- 7/10/2006 -- 1 comments -- printer friendly -- become a member




        Win SQL Books  -----  SharePoint Tips  -----  Live Webcast - SQL Backup Mistakes  -----  Bookmark and Share        

Problem
We have been running SQL Server 2000 for a few years and the transaction log file has become very large for some of our databases.  In some circumstances, the transaction log is a more than 5 times larger than our database. How can I reduce the size of this file?

Solution
Most likely, the root cause for the continuous transaction log growth is related to the database recovery model being set to 'full' for your user defined databases without issuing regularly scheduled transaction log backups.  The full recovery model configuration is maintaining all of the before and after records in the transaction log until the transaction log is backed up.  Most likely, you are not backing up the transaction log on a regular basis i.e. hourly, daily, etc. to support a high availability solution such as log shipping.

With these items in mind, it is time to make some changes to your SQL Server user defined databases and get your transaction logs to a manageable size.  Let's walk through each of these steps one at a time.  Keep in mind that since you are not performing transaction log backups that this process could be completed at an as needed time, but the preference would be during a maintenance window.

Note - These commands can be run in SQL Server management tool of your choice and replace the '[YourDatabaseNameHere]' text with the needed user defined database name.
 

First, review the transaction log size prior to the shrinking process.

USE [YourDatabaseNameHere]
GO
SELECT *
FROM sysfiles
WHERE name LIKE '%LOG%'
GO
 

Second, set the database recovery model to 'simple'. 

USE [YourDatabaseNameHere]
GO
ALTER DATABASE [YourDatabaseNameHere] SET RECOVERY SIMPLE
GO
 

Third, issue a checkpoint against the database to write the records from the transaction log to the database.

USE [YourDatabaseNameHere]
GO
CHECKPOINT
GO
 

Fourth, truncate the transaction log.

USE [YourDatabaseNameHere]
GO
BACKUP LOG [YourDatabaseNameHere] WITH NO_LOG
GO
 

Fifth, record the logical file name for the transaction log to use in the next step.

USE [YourDatabaseNameHere]
GO
SELECT Name
FROM sysfiles
WHERE name LIKE '%LOG%'
GO 

Sixth, to free the unused space in your transaction log and return the space back to the operating system, shrink the transaction log file.

USE [YourDatabaseNameHere]
GO
DBCC SHRINKFILE ([FileNameFromPreviousStep], [NeededFileSize])
GO
 

Seven, review the database transaction log size to verify it has been reduced.

USE [YourDatabaseNameHere]
GO
SELECT *
FROM sysfiles
WHERE name LIKE '%LOG%'
GO

Next Steps

  • Review your key SQL Server databases to determine if the transaction log growth is out of control.
  • Review this code and modify it for one of your databases.
  • Once the scripts are modified, test the scripts in a test environment to ensure they meet your needs.
  • Schedule time to shrink your databases and communicate the configuration changes.
  • Continue to monitor the database sizes and the available disk space on your servers.
     
Readers Who Read This Tip Also Read Comment or Ask Questions About This Tip Twitter This Tip!


Sponsor Information
Free SQL Server performance monitoring dashboard – Idera SQL check

The SQL Toolbelt – all 13 Red Gate SQL Server Tools.

Is your SQL Server sick? Get on the road to recovery. Innovative SQL DBA consultants.

Stop here to prepare for your next SQL Server interview!

Top 10 SQL Server Backup Mistakes and How to Avoid Them web cast - February 10, 2010

Become a member of the MSSQLTips community

Are you learning SharePoint too? Click here to check out MSSharePointTips.com...

Free whitepaper - Managing Complex Database Changes


 

 

Idera - SQL safe backup

Need more space for your backups? Idera has announced the latest edition of SQL safe, their award-winning backup and recovery solution. SQL safe v6.0 includes brand new compression algorithms developed with some of the leading compression experts in the world. Plus, SQL safe 6.0 continuously optimizes compression to give you the fastest possible backup with the highest possible compression, every time you do a backup.

Download now!



More SQL Server Tools
SQL defrag manager

SQL Backup

SQL compliance manager

SQL diagnostic manager

SQL Data Generator




Copyright (c) 2006-2010 Edgewood Solutions, LLC All rights reserved
privacy statement | disclaimer | copyright | advertise | write for mssqltips | feedback | about
Some names and products listed are the registered trademarks of their respective owners.