1

We had a production level event over the weekend where execution of a function suddenly went from MS to nearly a minute.

Unfortunately, SQL wasn't able to execute the ALTER Function and it kept 'spinning' due to the high volume of queries calling the function and the CPU hit critical 100% and the database became unusable/instable.

Ultimately the fastest resolution was to reboot the server.

However, is there a better/faster way to force the RECOMPILE that wouldn't hang?

I've found a number of articles on RECOMPILE but nothing along the lines of the hanging and being blocked.

Attempts to KILL the individual queries resulted in whack-a-mole and couldn't clear them out fast enough.

Thanks

3
  • What RDBMS are you using? Commented Jan 14, 2019 at 16:35
  • SQL Server 2012 SP3
    – MikeL
    Commented Jan 14, 2019 at 16:52
  • Did you look at wait stats before rebooting the server? What diagnostics did you run?
    – Hannah Vernon
    Commented Jan 14, 2019 at 16:58

1 Answer 1

2

...Ultimately the fastest resolution was to reboot the server. ...Attempts to KILL the individual queries resulted in whack-a-mole and couldn't clear them out fast enough.

There is no need to reboot server or kill sessions manually when you want to have an exclusive access to database, you can use ALTER DATABASE ... SET SINGLE_USER WITH ROLLBACK IMMEDIATE and than issue your ALTER FUNCTION.

To remove individual plan from cache you can use DBCC FREEPROCCACHE(plan_handle) with the plan_handle you are interested in, see Example A. Clearing a query plan from the plan cache here DBCC FREEPROCCACHE (Transact-SQL)

1
  • In a perfect world I agree that would allow the ALTER FUNCTION/DBCC FREEPROCCACHE to execute. Unfortunately, I suspectnot all of our apps are self-aware enough to reconnect once the SET MULTI_USER is executed. I will give it a try if there is a next time. Thanks
    – MikeL
    Commented Jan 15, 2019 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.