Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2005, 09:12 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Keeping transaction logs down to a reasonable size

I've noticed that the transaction logs for my SQL Server databases just keep growing and growing. I know that there is an option to constrain the log file size, but this sounds like a terrible idea - what happens when all the allocated space is used up?

Here is what I want to do -

1) Set up a system whereby the transaction logs are backed up nightly.

2) Once the logs have been backed up, shrink the actual transaction logs down to a reasonable size (like a couple of gigs or something)

Is this possible? If so, how do I do it? Keep in mind that I am not a DBA.

Thanks.
 
Old August 23rd, 2005, 09:39 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Run this script as a scheduled job in the SQL Server from the Master database


BACKUP LOG database_name WITH TRUNCATE_ONLY
WAITFOR DELAY '00:00:05'
DBCC SHRINKFILE(db_name, 120)


Where database_name is the name of your database.

The "BACKUP LOG" line is used to truncate the transaction log of the database.

The "WAITFOR" line is used to give the previous step time to complete before the next step in the job executes.
 
Old August 23rd, 2005, 09:54 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the suggestion, shahchi1.

Will that script create an actual backup of the transaction log? If so, where will it put the backup?

Also, we have a sql server agent "maintenance plan" job that runs nightly and makes static dumps of our database. Should we modify this job to also make backups of our transaction logs? Or is it safe to backup the transaction logs seperately, after our "maintenance plan" has finished executing?
 
Old August 23rd, 2005, 12:31 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No it will only truncate the transaction log if you want to backup your transaction log then specify the log backup device using sp_addumpdevice

USE master
EXEC sp_addumpdevice 'disk', 'MyDbLog1',
'c:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\MyDbLog1.dat'

BACKUP LOG database_name TO MyDbLog1 TRUNCATE_ONLY

Is you current "maintenance plan" use DUMP DATABASE and DUMP TRANSACTION statements? They are synonymous with BACKUP DATABASE and BACKUP LOG statements. Support for the DUMP DATABASE and DUMP TRANSACTION statements may be removed in a future release.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Transaction Logs kilika SQL Server 2000 17 September 30th, 2004 09:26 AM
Keeping a Form Maximized shepston Access 2 August 4th, 2003 12:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.