Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL 2008 log files

Posted on 2014-10-29
9
Medium Priority
?
209 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 40

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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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
 
LVL 40

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 23

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 23

Accepted Solution

by:
Steve Wales earned 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

972 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