Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
226 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 71

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

721 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