patternsqlMinor
Limit user memory usage
Viewed 0 times
limitmemoryuserusage
Problem
I'm using SQL Server 2014. There are some users who can query the tables. The problem is, that most of the time these queries use a lot of memory. I want to know if there is any way to limit resources per user?
There is not a specific query. I just want to control users. Sometimes they do crazy things.
There is not a specific query. I just want to control users. Sometimes they do crazy things.
Solution
As stated before, you can use Resource Governer to limit memory usage for specific users.
To summarize shortly the steps you should do:
-
Create a resource pool. This example has max 30% of memory, be careful with that.
-
Create a workload group which will use resource pool.
-
You should define a Classifier function to tell SQL Server who is gonna be in this group.
-
Lastly to enable Resource Governor
You can find additional info at Resource Governor at MSDN
To summarize shortly the steps you should do:
-
Create a resource pool. This example has max 30% of memory, be careful with that.
CREATE RESOURCE POOL UserMemoryPool
WITH
( MIN_MEMORY_PERCENT=0,
MAX_MEMORY_PERCENT=30)
GO-
Create a workload group which will use resource pool.
CREATE WORKLOAD GROUP UserMemoryGroup
USING UserMemoryPool;
GO-
You should define a Classifier function to tell SQL Server who is gonna be in this group.
CREATE FUNCTION dbo.UserClassifier()
RETURNS SYSNAME WITH SCHEMABINDING
AS
BEGIN
DECLARE @Workload AS SYSNAME
IF(SUSER_NAME() = 'UserNameToLimit')/*Specify the user*/
SET @Workload = 'UserMemoryGroup'
ELSE
SET @Workload = 'default'
RETURN @Workload
END
GO-
Lastly to enable Resource Governor
USE master
GO
ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = dbo.UserClassifier);
GO
ALTER RESOURCE GOVERNOR RECONFIGURE;You can find additional info at Resource Governor at MSDN
Code Snippets
CREATE RESOURCE POOL UserMemoryPool
WITH
( MIN_MEMORY_PERCENT=0,
MAX_MEMORY_PERCENT=30)
GOCREATE WORKLOAD GROUP UserMemoryGroup
USING UserMemoryPool;
GOCREATE FUNCTION dbo.UserClassifier()
RETURNS SYSNAME WITH SCHEMABINDING
AS
BEGIN
DECLARE @Workload AS SYSNAME
IF(SUSER_NAME() = 'UserNameToLimit')/*Specify the user*/
SET @Workload = 'UserMemoryGroup'
ELSE
SET @Workload = 'default'
RETURN @Workload
END
GOUSE master
GO
ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = dbo.UserClassifier);
GO
ALTER RESOURCE GOVERNOR RECONFIGURE;Context
StackExchange Database Administrators Q#157198, answer score: 4
Revisions (0)
No revisions yet.