Kill Query running more then 5 hours

  • How to write an automated query which is running for more then 5 hours should be killed automatically

     

    Thanks


    Dimpal Patel

  • I think you could use the "Use query governor to prevent queries exceeding specified cost" server setting to indirectly limit it. I'm not very familiar with it and so can't vouch for how usefull it may be. You could also schedule a job to run every 5 - 15 minutes that queries the sysprocesses table and examines the cpu, login_time, or last_batch fields to determine which spids need to be killed and then kill them. I've never done that before either, though.

  • From books online.

    Use the query governor cost limit option to specify an upper limit for the time in which a query can run. Query cost refers to the estimated elapsed time, in seconds, required to execute a query on a specific hardware configuration.

    I think it looks at the estimated cost and not the actual execution time. It won't kill the query but will not execute it if the estimated cost is found to be greater than the value specified.

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply