December 7, 2015 at 10:23 am
I have Index Rebuild job which usually runs everyweek and takes about 15-20 minutes (Average time). Couple of times, it ran for 2+ hours. I found this script online http://devinknightsql.com/2012/07/07/identifying-long-running-sql-agent-jobs-script/ and I was hoping that it 'd work but it didn't. I created a small job which was running every minute. Select * from sometable
. Then I edited the job WAITFOR delay '000:05:00'
Select * from sometable
Then executed the SP but it returned 0 value.
So this is where I need some help.
I 'd like to be notified if the job runs for a long time. How can I accomplish that?
December 7, 2015 at 11:06 pm
Are you scheduling this operation with Sql Agent Job, if yes then there may not be a direct solution for you however you can use some 3rd party Sql Monitors like SqlSentry (http://www.sqlsentry.com/)
However, I would suggest a workaround for this.
In the procedure or the query where you are rebuilding index, create some table with a flag column like (Rebuild Status) and a starttime column
At the start of rebuilding operation, update the flag value as 'Started' and update the start time,
and post completion of rebuilding update the status as 'Completed'
Create a second job, where you keep polling this flag value with started and start time, compare with current time. If that exceeds the time you desire like (15-20 mins) raise a custom error message.
This part you can do with a small T-Sql code.
Then you can even configure an email associated with that custom error.
I guess this work around will save you from buying some paid solutions or if someone has a better solution most welcome 🙂
December 7, 2015 at 11:28 pm
Chitown (12/7/2015)
I have Index Rebuild job which usually runs everyweek and takes about 15-20 minutes (Average time). Couple of times, it ran for 2+ hours. I found this script online http://devinknightsql.com/2012/07/07/identifying-long-running-sql-agent-jobs-script/ and I was hoping that it 'd work but it didn't. I created a small job which was running every minute.Select * from sometable
. Then I edited the jobWAITFOR delay '000:05:00'
Select * from sometable
Then executed the SP but it returned 0 value.
So this is where I need some help.
I 'd like to be notified if the job runs for a long time. How can I accomplish that?
Ok... let's just say that you get a script working to do such a notification for your index rebuild job and it sends you an email that the job is or has taken longer than expected....
... just exactly what are you going to do about it when you get the email?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 8, 2015 at 10:02 am
Jeff Moden (12/7/2015)Ok... let's just say that you get a script working to do such a notification for your index rebuild job and it sends you an email that the job is or has taken longer than expected....
... just exactly what are you going to do about it when you get the email?
I will try to find out why it is taking that long. Maybe re-run the job some other time. Maybe there is a process being blocked out by another process, etc
December 8, 2015 at 10:23 am
What are you using for reindexing? A maintenance plan?
There are a number of free maintenance solutions that log what they are doing.
They capture the indexes that are fragmented, and then only reindex the things that need it.
We use:
That way, you can simply look in the logs, or, in the case of Ola's scripts, the logging table to see exactly what has happened and why.
The simple answer is that there are more things that needed to be re-indexed. What caused the indexes to become fragmented in the first place?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
December 8, 2015 at 12:35 pm
These 2 parameters can be particularly useful in your case:
https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html
TimeLimitSet the time, in seconds, after which no commands are executed. By default, the time is not limited.
LockTimeout
Set the time, in seconds, that a command waits for a lock to be released. By default, the time is not limited.
The LockTimeout option in IndexOptimize uses the SET LOCK_TIMEOUT set statement in SQL Server.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply