I have a SQL Environment of which I am sysadmin. This Environment includes the Company data warehouse. I conduct many different jobs from this Environment, and it is also Another sysadmin which has access to it.
Seeing that it contains the data warehouse, some users from the production team has access to it as well.
The underlying raw data is very spread out. The data comes from many different sources, which sometimes requires excessive use of OUTER JOIN
s, Temp Tables
, Procedures
etc. in order to fetch the data of interest.
I have seen that some users in the production team has sometimes done massive queries, resulting in TempDB growing uncontrollably by 50+ GB, eventually resulting in the server shutting down (thus far, we have the SQL servers and TempDB on the same drive).
Is there a way to prohibit the production team of using too big queries, while not putting the same restrictions on the sysadmins, as there is sometimes neccessary to conduct TempDB extensive queries given the complex raw data structure?
I do not want to hinder the production team of using/creating Stored procedures
, Temp Tables
etc. I just want to investigate if there is an option to restrict execution time / TempDB usage.
Best Answer
You cannot limit some users for use the certain amount of tempdb only, instead, you can put the limit to it's max size.
Anyway, putting tempdb at the same disk with your system files is a bad idea.
You can monitor who is consuming your tempdb making smth like this:
go
go
Here I created a view using sys.dm_db_task_space_usage that shows me in real time who is using more than 1Gb of tempdb now. Then I put the query that reads from this view in a job running every 5 minutes, so it captures every query along with it's owner if it consumes more than 1Gb. Then it's up to you how you want to react to it. My actions are simple: tempdb has a limited size (100Gb) so it's impossible to overflow it. Every violator is just rolling back receiving smth like this:
At the same time every attempt to overflow it is captured by my job. So I can easily see who it was and what he was doing, and take actions.