Unfortunately, SQL Server’s management studio doesn’t provide you with a simple way to script your resource pools and resource groups. If you want to do this you’ll first have to script all the groups, and then the pools one by one in the correct order. To recreate them you have to do the same but in a reverse order.
This SQL script does just that, it generates the scripts needed to recreate your resource groups and pools in the correct order. This is extremely useful in Always-on scenario’s as it provides you with a script that can be run on the primary node, and the result on any secondary node(s) creating a completely identical resource configuration for your resource governors.
The generated scripts can also be used as post scripts for application deployment or for documentation purposes. Please note that it does NOT script the configuration of your resource governor nor will it script your classification function. This is not within the scope of this script.
The difficulty for this script was to make the script generate the statements in the correct order, and to take into consideration the edition changes in the resource governor.
The script has two self-explaining parameters:
DECLARE @Drop bit=1 DECLARE @Create bit=1 DECLARE @CMD nvarchar(4000) declare @version int set @version = (SELECT convert (int,REPLACE (LEFT (CONVERT (varchar, SERVERPROPERTY ('ProductVersion')),2), '.', ''))) CREATE TABLE #Command (pk int identity(1,1) PRIMARY KEY,Command nvarchar(4000)) IF @Drop=1 BEGIN IF NOT Exists (select * from tempdb.sys.objects where name like'#DROPS%' and type='U') BEGIN CREATE TABLE #DROPS (Group_id int,Pool_id int,IsActive bit, Command nvarchar(4000)) END ELSE BEGIN Truncate table #DROPS END INSERT INTO #DROPS Select Group_id,Pool_id,1, 'use [master]; DROP WORKLOAD GROUP '+QUOTENAME(wg.name)+';' FROM sys.resource_governor_workload_groups wg where group_id > 2 INSERT INTO #DROPS Select 0,Pool_id,1, 'use [master]; BEGIN TRY DROP RESOURCE POOL '+QUOTENAME(name)+' END TRY BEGIN CATCH END CATCH;' FROM sys.dm_resource_governor_resource_pools where Pool_id > 2 INSERT INTO #Command Select Command From #Drops order by Pool_id asc,Group_id desc END IF @Create = 1 BEGIN IF NOT Exists (select * from tempdb.sys.objects where name like'#CREATES%' and type='U') BEGIN CREATE TABLE #CREATES (Group_id int,Pool_id int, Command nvarchar(4000)) END SET @CMD='Select 0,Pool_id,''use [master]; BEGIN TRY CREATE RESOURCE POOL ''+QUOTENAME(name)+'' WITH (''+ ''min_cpu_percent=''+CAST(min_cpu_percent as varchar(3))+'', ''+ ''max_cpu_percent=''+CAST(max_cpu_percent as varchar(3))+'', ''+ ''min_memory_percent=''+CAST(min_memory_percent as varchar(3))+'', ''+ ''max_memory_percent=''+CAST(max_memory_percent as varchar(3))+'', ''+ '+ CASE WHEN @version > 10 THEN '''cap_cpu_percent=''+CAST(cap_cpu_percent as varchar(3))+'', ''+ 'ELSE '' END+ CASE WHEN @version > 11 THEN '''min_iops_per_volume=''+CAST(min_iops_per_volume as varchar(3))+'', ''+ 'ELSE '' END+ CASE WHEN @version > 11 THEN '''max_iops_per_volume=''+CAST(max_iops_per_volume as varchar(3))+'', ''+ 'ELSE '' END+ '''AFFINITY SCHEDULER = AUTO)''+'+ ''' END TRY BEGIN CATCH END CATCH ''' + 'FROM sys.dm_resource_governor_resource_pools where Pool_id > 2' PRINT @cmd INSERT INTO #CREATES exec sp_executesql @cmd INSERT INTO #CREATES Select wg.group_id,wg.pool_id, 'use [master]; BEGIN TRY CREATE WORKLOAD GROUP '+QUOTENAME(wg.name)+' WITH (' + 'group_max_requests='+CAST(group_max_requests as varchar(4))+', '+ 'importance='+importance+', '+ 'request_max_cpu_time_sec='+CAST(request_max_cpu_time_sec as varchar(5))+', '+ 'request_max_memory_grant_percent='+CAST(request_max_memory_grant_percent as varchar(5))+', '+ 'request_memory_grant_timeout_sec='+CAST(request_memory_grant_timeout_sec as varchar(5))+', '+ 'max_dop='+CAST(max_dop as char(2))+') USING '+QUOTENAME(rp.name)+' END TRY BEGIN CATCH END CATCH;' FROM sys.resource_governor_workload_groups wg inner join sys.dm_resource_governor_resource_pools rp on rp.pool_id=wg.pool_id where wg.group_id > 2 INSERT INTO #Command Select Command From #CREATES order by Pool_id desc,Group_id asc END GO Select * From #Command GO IF Exists (select * from tempdb.sys.objects where name like '#DROPS%' and type='U') BEGIN DROP TABLE #DROPS END GO IF Exists (select * from tempdb.sys.objects where name like '#CREATES%' and type='U') BEGIN DROP TABLE #CREATES END GO DROP TABLE #Command
Cookie | Duration | Description |
---|---|---|
ARRAffinity | session | ARRAffinity cookie is set by Azure app service, and allows the service to choose the right instance established by a user to deliver subsequent requests made by that user. |
ARRAffinitySameSite | session | This cookie is set by Windows Azure cloud, and is used for load balancing to make sure the visitor page requests are routed to the same server in any browsing session. |
cookielawinfo-checkbox-advertisement | 1 year | Set by the GDPR Cookie Consent plugin, this cookie records the user consent for the cookies in the "Advertisement" category. |
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
CookieLawInfoConsent | 1 year | CookieYes sets this cookie to record the default button state of the corresponding category and the status of CCPA. It works only in coordination with the primary cookie. |
elementor | never | The website's WordPress theme uses this cookie. It allows the website owner to implement or change the website's content in real-time. |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Cookie | Duration | Description |
---|---|---|
__cf_bm | 30 minutes | Cloudflare set the cookie to support Cloudflare Bot Management. |
pll_language | 1 year | Polylang sets this cookie to remember the language the user selects when returning to the website and get the language information when unavailable in another way. |
Cookie | Duration | Description |
---|---|---|
_ga | 1 year 1 month 4 days | Google Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors. |
_ga_* | 1 year 1 month 4 days | Google Analytics sets this cookie to store and count page views. |
_gat_gtag_UA_* | 1 minute | Google Analytics sets this cookie to store a unique user ID. |
_gid | 1 day | Google Analytics sets this cookie to store information on how visitors use a website while also creating an analytics report of the website's performance. Some of the collected data includes the number of visitors, their source, and the pages they visit anonymously. |
ai_session | 30 minutes | This is a unique anonymous session identifier cookie set by Microsoft Application Insights software to gather statistical usage and telemetry data for apps built on the Azure cloud platform. |
CONSENT | 2 years | YouTube sets this cookie via embedded YouTube videos and registers anonymous statistical data. |
vuid | 1 year 1 month 4 days | Vimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. |
Cookie | Duration | Description |
---|---|---|
ai_user | 1 year | Microsoft Azure sets this cookie as a unique user identifier cookie, enabling counting of the number of users accessing the application over time. |
VISITOR_INFO1_LIVE | 5 months 27 days | YouTube sets this cookie to measure bandwidth, determining whether the user gets the new or old player interface. |
YSC | session | Youtube sets this cookie to track the views of embedded videos on Youtube pages. |
yt-remote-connected-devices | never | YouTube sets this cookie to store the user's video preferences using embedded YouTube videos. |
yt-remote-device-id | never | YouTube sets this cookie to store the user's video preferences using embedded YouTube videos. |
yt.innertube::nextId | never | YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen. |
yt.innertube::requests | never | YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen. |
Cookie | Duration | Description |
---|---|---|
WFESessionId | session | No description available. |