Solved

How can I create a SP to Shrink the log? to be able to call it from a SQL Job.

Posted on 2008-10-28
9
225 Views
Last Modified: 2013-11-30
Hello:

I'd like to create a SP to shrink an SQLlog and then call it from a job, in the step after backing up the log.

create PROCEDURE truncatelog
DBCC SHRINKFILE (CEGE_SQL_Log, 1)

This gives me a syntax error.

Regards,
Joseph
0
Comment
Question by:CEGE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Author Comment

by:CEGE
ID: 22826827
hello:

What I'd like to do is do a database backup once a day and do log backups 3 times per day, and after each log backup I'd like to truncate the log, I have the log file limit set to 5GB, not unlimited growth. This seems to cover all of the bases should something bad happen. Is this correct? and not freeze up the server should the limit be breached.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 22826900
You should be able to use dbcc directly in the job steps. However, if you want to use a procedure, you will have to use something like this:

create PROCEDURE truncatelog
begin
  DBCC SHRINKFILE (CEGE_SQL_Log, 1)
end

Open in new window

0
 
LVL 1

Author Comment

by:CEGE
ID: 22827344
1) in the job step, it gave me this error:

Cannot shrink log file 2 (Goldmine_Log) because all logical log files are in use.

2) and it gave me a syntax error with Begin trying to create the SP:

What am I missing here?

thanks,
Joseph
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22827482
More importantly you should not be shrinking your log file.  Constantly growing and shrinking your file is not only extremely inefficient, it will fragment the ldf file across the disk making use of it by SQL server slower.

Your best bet is to find the maximum size you will EVER need, add 10%, and set it to a fixed size.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22827668
Since you are truncating the log, it would appear you have no interest in point-in-time restore, so why not set your Recovery Model to Simple, that way you
A) Don't have to backup your Transaction Log and more importantly
B) Don't have to shrink it repeatedly, either, which is a big no, no.
0
 
LVL 1

Author Comment

by:CEGE
ID: 22829204
hello acperkins:

The deal is that I do want a point in time restore and I also do want to do backups of the logs every 3 hours. But what I am not so sure about is the maximum size of the log, recently I set it the 1GB and it got hit after 2 weeks. I somehow would like to do the log backups and then have the file be as small as possible, but I don't want to repeatedly shrink it either. Does it get done automatically so that the max is never reached¿ What is the Best Practice for dealing with this? What do you do?
thanks,
Joseph
0
 
LVL 22

Expert Comment

by:PedroCGD
ID: 22829666
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 22830496
From what I've read here, my guess is that real issue isn't "How do I shrink the log file"... the real issue is "How to I keep the log file from growing"
If you're up for some light reading, I'd suggest the following article as it explains the steps required to manage log file growth: http://home.hot.rr.com/graye/Articles/SQL_LogMaintenance.htm
0
 
LVL 1

Author Closing Comment

by:CEGE
ID: 31510960
Finally, this is just what I was looking for. Thank you.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

615 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