SQL2008新特性Resource Governor(3)
8. 创建两个数据库,用来做测试
IF DB_ID ('MarketingDB') IS NULL
CREATE DATABASE MarketingDB;
GO
IF DB_ID ('DevelopmentDB') IS NULL
CREATE DATABASE DevelopmentDB;
GO
9. 创建classifier function
IF OBJECT_ID ('dbo.MyClassifier') IS NOT NULL
DROP FUNCTION dbo.MyClassifier;
GO
CREATE FUNCTION dbo.MyClassifier ()
RETURNS SYSNAME WITH SCHEMABINDING
AS
BEGIN
DECLARE @GroupName SYSNAME;
IF ORIGINAL_DB_NAME () = 'MarketingDB'
SET @GroupName = 'MarketingGroup';
ELSE IF ORIGINAL_DB_NAME () = 'DevelopmentDB'
SET @GroupName = 'DevelopmentGroup';
ELSE SET @GroupName = 'Default';
RETURN @GroupName;
END;
GO
这里,Sqlserver2008对于 Resource Governor 的设计方式,很类似代理。Resource Governor 通过一个方法来绑定数据库对象到WorkLoad Group ,这个方法需要外部给出定义,并且手动绑定到Resource Governor 上面,定义方式可以参照上面代码。分别将两个测试用数据库绑定到各自的Group中,其他的数据库绑定到Default上面。
10. 绑定Classifier Function 到Resource Governor上面。
ALTER RESOURCE GOVERNOR
WITH (CLASSIFIER_FUNCTION = dbo.MyClassifier);
GO
11. 更新Resource Governor 配置信息
ALTER RESOURCE GOVERNOR RECONFIGURE;
GO