We run maintenance windows weekly and monthly. Some of our maintenance windows are online and the last thing we want is our scripts to block live queries from our applications.
Is there a way to set the priority of a query so that it cannot cause other queries to block for more than X seconds?
Example:
I know there is a similar functionality with deadlocks (set deadlock victim to low).
Thanks!
Best Answer
Microsoft introduced the new Low Priority Lock Wait option for Index rebuilds in SQL Server 2014. Not sure what SQL Server version you are running.
Index rebuild using 'low priority lock wait':
Check out Paul Randal's excellent article here Low Priority Wait and Testing Index rebuilds with Low Priority Wait by Kendra Little for clear explanation.
That's specific for Index maintenance, I am assuming your maintenance plans does include Integrity checks and other stuff too.
An option would be writing some TSQL code to monitor blocking and and create and schedule a SQL agent job to automatically kill the 'low priority session' based on the SQL text its running.
If you are experiencing issues caused by deadlocks, you could probably lower the Deadlock priority value to see if that helps.
Depending on the type of resource contention, you can also try limiting the resources for specific logins using Resource Governor.
If you are using custom maintenance plans, you probably need to look into and start using Ola Hallengren's Maintenance solution.