Solved

SQL 2008 log files

Posted on 2014-10-29
9
192 Views
Last Modified: 2014-10-30
New SQL 2008 server.  I back up my databases, I back up my log files.  In SQL 2003 I remember this would reduce the size of the log files until the next back up window.  It doesn't reduce the log file size in 2008.  Does it work different?  Am I missing a step?
0
Comment
Question by:damelahn
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 40411215
"In SQL 2003 I remember this would reduce the size of the log files until the next back up window."
First there's no SQL 2003 - maybe 2005 and secondly it "...would NOT reduce the size of the log files until the next back up window." but recycle the space inside the log so it can be re-used without the log to grow.

What is the Recovery option of the database where you are having issues with the T-Log file?
How often do you backup the T-log?
0
 
LVL 7

Expert Comment

by:wnross
ID: 40411241
If you have only one log file (normal) you will be unable to shrink the transaction log manually, since the server needs to be able to close a file to shrink it.  Note that truncation occurs automatically only under the simple recovery model, so if you are not using that you will not see a change in file size.

Try adding a second log file to the database then issue a DBCC shrinkfile command
USE UserDB;
GO
DBCC SHRINKFILE (DataFile1, 7);
GO

Open in new window


Copied right from MSDN:
If the shrink operation runs without error, but the file does not appear to have changed in size, verify that the file has adequate free space to remove by performing one of the following operations:

Run the following query.
   
SELECT name ,size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS AvailableSpaceInMB
    FROM sys.database_files;

Open in new window

0
 
LVL 1

Author Comment

by:damelahn
ID: 40411284
Sorry, old server was sql 2000 (not 2003).  Recovery is set to Full and t-log backups run every 2 hrs during business hours.  

So you are saying the log file size will always increase and never decrease in this mode?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 40411310
>So you are saying the log file size will always increase and never decrease in this mode?
If you see the log file size increase even after taking the log backups, there seems like bigger transactions going one, could be more page splits, db shrinking or an increase in the no of transactions. make sure that auto shrink is not enables for the database; also you could try changing the log shipping to every 1 hr instead of 2 hrs. look for  other jobs like reindexing check db etc.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 39

Expert Comment

by:lcohan
ID: 40411333
Indeed - The T-Log file size will never decrease on its own unless you set the AUTOSHRINK database option (definitely NOT recommended)  to ON so the file size is automatically reduced OR you shrink the T-log file from the SSMS UI menu (not recommended) or by running a DBCC SHRINKFILE(dbnameHere_log) SQL command.


T-log SQL backups would only recycle the space inside the physical file and you could do it more often if you need to keep the size of the log under control OR switch the recovery mode to BULCK-LOGGED without ANY impact to your FULL/T-log and recovery planning OR you may even switch it to SIMPLE but that ONLY if your business model can accept less logging and implicit some data loss plus this SIMPLE recovery will impact your backups type and schedule.
0
 
LVL 22

Expert Comment

by:Steve Wales
ID: 40411517
Your transaction log file will grow to accommodate the volume of transactions that occur between your transaction log backups.  It is the backup of the log that marks the space in the TLog file able to be reused.  

Perform a log shrink after every backup is counter productive.  The space might be marked as able to be reused in the log file, this allowing a shrink, but if you have 20 GB of transactions in between log file backups, then it's just going to grow back to 20 GB.

If you are concerned about the size of your transaction log file, perform your log file backups on a more frequent basis - hourly, half hourly, whatever meets the needs of your business requirements (some people run log backups every 60 seconds).

If you know that volume of your transactions, you can size your log file accordingly ahead of time, and prevent automatic log file growth operations during peak periods (which is an expensive operation).
0
 
LVL 1

Author Comment

by:damelahn
ID: 40411962
I manually backed up one of the smaller DBs and the associated log file.  Switched the DB to Simple mode, waited a bit and then switched back to Full.  Now I have a brand new (tiny) log file.  Any harm done by using this method?
0
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 40411974
Switching a database to simple recovery mode breaks your recovery chain.  If it's a prod database, take a new full backup immediately.    That's not something you should really ever do.

If you are concerned about a bloated log file, please read this article: http://www.experts-exchange.com/Database/MS-SQL-Server/A_11077-How-to-shrink-a-bloated-log-file.html

It also includes links to several other references that will explain why your log file is growing, how to shrink it to reclaim space and then how to size it correctly to prevent the problem happening again.
0
 
LVL 7

Expert Comment

by:wnross
ID: 40411987
So you are saying the log file size will always increase and never decrease in this mode?
If your server is set to "Full Recovery" then the transaction logs can only be reduced in size after a transaction log backup. Eg:
BACKUP LOG [UserDb] TO  DISK = N'C:\Backup\UserDb.bak'
GO

Open in new window

If your file sizes are getting too large you might want to look at your database properties like autogrow and autoshrink, however the autoshrink property probably should only be used in development databases.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now