Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 add query to maintenance plan

Author  Topic 

10Dawg
Starting Member

46 Posts

Posted - 2012-01-17 : 10:39:05
I have a query that shrinks a log file down to 1GB. I want it run automatically after the nightly backups. How? Make it a stored procedure and add it to my maintenance plan? How do I change a query into a stored procedure?

If not, how else can I make it part of my nightly maintenance plan? Is there something already in place that I can just add? (Note that the query changes the backup type from full to simple and then back again after the shrink)

Thanks in advance.

10Dawg

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-01-17 : 10:48:52
Why? Needless shrinking of the log file is just bad.

http://blog.sqlauthority.com/2010/05/03/sql-server-shrinkfile-and-truncate-log-file-in-sql-server-2008/

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=147587

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

10Dawg
Starting Member

46 Posts

Posted - 2012-01-17 : 10:58:22
O yes, I forgot to mention it was 2008. I will do the links. Thanks.

10Dawg
Go to Top of Page

10Dawg
Starting Member

46 Posts

Posted - 2012-01-17 : 11:40:55
OK then let's back up a second (no pun intended). The problem is the logs files continue to grow. Our environment WAS NOT MY DESIGN, I want to say that up front. I inherited it. The Backup, BCPPath, dtShare, FTData, LDF, MDF do not go to the default location, they go a dedicated (nothing else on it) 3TB server. Right now I have 1.19TB free of 2.99TB on that server. I have 20 dbs with 12-15 active daily at any one point. The nature of the business is that a db may go dormant for a month or 2 and then become active again. Left unattended (except for zipping the DB Backups every morning and storing them elsewhere) That 1.19TB will be full in 2-3 weeks. I would like to do transactional backups hourly on the db that are active but I don't have the room. So I do a nightly backup (Shrink db, Rebuild Index, Check db, Backup db, in that order). But that doesn't address the log files that continue to grow unabated. So the bigger question is, How can I safely maintain this environment?

10Dawg
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-01-17 : 14:08:14
Gail is incredibly knowledgeable in this area. Try searching her blog. http://sqlinthewild.co.za/

Or here: http://www.sqlteam.com/forums/forum.asp?FORUM_ID=41

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-18 : 03:46:50
"I would like to do transactional backups hourly on the db that are active but I don't have the room."

So you don't need, or want, any log backups?

Change the Recovery Model from FULL to SIMPLE and then the log will automatically clear (i.e. become available for reuse, NOT Shrink) after each transaction is committed - if you have HUGE transactions then the Log file will still grow to accommodate the largest one.

(I've slightly oversimplified it, but that is the gist of it)

In SIMPLE Recovery Model you will have NO ability to recover to a point-in-time, so you will only be able to restore to your last full backup - but by the sounds of it you are in that position already?

Note that if you repeatedly shrink the files you cause both physical and logical fragmentation which adversely impact performance. In particular if you rebuild an index, to improve performance, and then SHRINK the database the index will no longer be contiguous and will be fragmented within the database file - the very thing that the index rebuild just fixed
Go to Top of Page
   

- Advertisement -