How to run A SQL Job Of Restart Of Server, SQL Server 2008 R2

Answered How to run A SQL Job Of Restart Of Server, SQL Server 2008 R2

  • Thursday, December 20, 2012 7:49 PM
     
     
    Basics: I'm running a SQL Server 2008 R2

    I am trying to run a SQL job or maintenance plan on the startup (restart) of a SQL Server.
    I’m trying to automate a Database Shrink job, which has to have exclusive access to the database to run. Realistically, the only time this happens is when the server is restarted, so I’m looking for a way to run a job on restart.

    As always, any help is greatly appreciated
    Thank you,

    David92595

All Replies

  • Thursday, December 20, 2012 7:58 PM
     
     

    Hello,

    You can schedule a SQL Server Agent job on startup of the Agent; not on SQL Server startup.

    See Schedule a Job => 6. For Schedule Type, select one of the following...


    Olaf Helper

    Blog Xing

  • Thursday, December 20, 2012 9:47 PM
    Moderator
     
     Proposed

    Shrinking a database does not require exclusive access to the database.  In addition, it is not advisable to shrink a database.  Unless you did major mainteance to delete a lot of data, the size is the size it needs to be.

  • Thursday, December 20, 2012 10:49 PM
     
     

    @ Tom

    I am aware it is not advisable to shrink  a database.  However, I can not have my database crash on me again  because the log files have taken up well over 10 Gb of space on my server, in conjunction with the reality I am forced to face that I work in a under funded IT department in which we can not get approved for more disk space...

    I'm not sure why, but when I have tried to run a shrink task in the past it timed out, any idea's?  It ran this time...

    Thank you for your help,

    David 92595

  • Friday, December 21, 2012 6:20 AM
     
     Answered

    crash on me again  because the log files have taken up well over 10 Gb of space on my server,


    When the log file grows then eighter switch the Recovery Model of the database to "Simple" or run frequently a log backup to release the space (VLF) in the log file.

    Olaf Helper

    Blog Xing

  • Friday, December 21, 2012 6:44 AM
     
     Answered

    Shrink only the log file not the data files.

    You may read the below articles:

    http://www.sqlskills.com/blogs/paul/post/why-you-should-not-shrink-your-data-files.aspx

    http://www.sqlskills.com/blogs/paul/post/a-sql-server-dba-myth-a-day-(930)-data-file-shrink-does-not-affect-performance.aspx


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

  • Friday, December 28, 2012 7:56 PM
     
     

    I have set up a log backup to run on a schedule, which should take care of my issue.

    Thank you for you helpful advise and links.  I hope others read this thread and are able to learn from it.

    David92595