Skip to content

Commit ed64821

Browse files
Updated sample to fit GA version of API
1 parent 02e139c commit ed64821

1 file changed

Lines changed: 112 additions & 62 deletions

File tree

Lines changed: 112 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,112 @@
1-
{
2-
"version": "0.2",
3-
"name": "Custom Checks Ruleset",
4-
"checks":[
5-
{
6-
"target": {
7-
"type": "Database",
8-
"platform": "Windows"
9-
},
10-
"id": "Custom_AutoUpdateStats",
11-
"tags": [ "InternalBestPracticeSet", "Performance", "CustomRuleset" ],
12-
"displayName": "Custom check: Auto-Update Statistics should be on",
13-
"description": "The query optimizer needs up-to-date and accurate statistics in order to generate good plans. In most cases, it's best to let SQL Server maintain the statistics. If you turn 'Auto Create Stats' and 'Auto Update Stats' off, then it is up to you to keep the statistics up-to-date somehow. Failure to do so will lead to poor query performance. Most applications should have these options ON.\n \n When the Auto Update Statistics setting is ON, the query optimizer updates statistics when they are used by a query and when they might be out-of-date. Statistics become out-of-date after insert, update, delete, or merge operations change the data distribution in the table or indexed view. The query optimizer determines when statistics might be out-of-date by counting the number of data modifications since the last statistics update and comparing the number of modifications to a threshold. The threshold is based on the number of rows in the table or indexed view. The query optimizer checks for out-of-date statistics before compiling a query and before executing a cached query plan. Before compiling a query, the query optimizer uses the columns, tables, and indexed views in the query predicate to determine which statistics might be out-of-date. Before executing a cached query plan, the Database Engine verifies that the query plan references up-to-date statistics. The AUTO_UPDATE_STATISTICS option applies to statistics created for indexes, single-columns in query predicates, and statistics that are created by using the CREATE STATISTICS statement. This option also applies to filtered statistics.",
14-
"message": "Turn Auto-Update Statistics option on to improve query performance.",
15-
"helpLink": "https://blogs.msdn.microsoft.com/buckwoody/2009/08/18/sql-server-best-practices-auto-create-and-auto-update-statistics-should-be-on-most-of-the-time/",
16-
"probes": [ "Custom_DatabaseConfiguration" ],
17-
"condition": "@is_auto_update_stats_on"
18-
},
19-
{
20-
"target": {
21-
"type": "Database",
22-
"version": "[12.0,)",
23-
"platform": "Windows",
24-
"name": { "not": "/^(master|msdb)$/" }
25-
},
26-
"id": "Custom_QueryStoreOn",
27-
"tags": [ "InternalBestPracticeSet", "Performance", "CustomRuleset" ],
28-
"displayName": "Custom check: Query Store should be on",
29-
"description": "The SQL Server Query Store feature provides you with insight on query plan choice and performance. It simplifies performance troubleshooting by helping you quickly find performance differences caused by query plan changes. Query Store automatically captures a history of queries, plans, and runtime statistics, and retains these for your review. It separates data by time windows so you can see database usage patterns and understand when query plan changes happened on the server.",
30-
"message": "Turn Query Store option on to improve query performance troubleshooting.",
31-
"helpLink": "https://docs.microsoft.com/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store",
32-
"probes": [ "Custom_DatabaseConfiguration" ],
33-
"condition": "@is_query_store_on"
34-
}
35-
],
36-
"probes":{
37-
"Custom_DatabaseConfiguration": [
38-
{
39-
"type": "SQL",
40-
"target": {
41-
"type": "Database",
42-
"version": "(,12.0)",
43-
"platform": "Windows"
44-
},
45-
"implementation": {
46-
"query": "SELECT db.[is_auto_create_stats_on] AS is_auto_create_stats_on, db.[is_auto_update_stats_on] AS is_auto_update_stats_on, 0 AS is_query_store_on FROM sys.databases AS db WHERE db.[name]='@DatabaseName'"
47-
}
48-
},
49-
{
50-
"type": "SQL",
51-
"target": {
52-
"type": "Database",
53-
"version": "[12.0,)",
54-
"platform": "Windows"
55-
},
56-
"implementation": {
57-
"query": "SELECT db.[is_auto_create_stats_on] AS is_auto_create_stats_on, db.[is_auto_update_stats_on] AS is_auto_update_stats_on, db.[is_query_store_on] AS is_query_store_on FROM sys.databases AS db WHERE db.[name]='@DatabaseName'"
58-
}
59-
}
60-
]
61-
}
62-
}
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "0.2",
4+
"name": "Custom Checks Ruleset",
5+
"rules":[
6+
{
7+
"target": {
8+
"type": "Database",
9+
"platform": "/^(Windows|Linux)$/",
10+
"engineEdition": "OnPremises, ManagedInstance"
11+
},
12+
"id": "Custom_AutoCreateStats",
13+
"itemType": "definition",
14+
"tags": [ "CustomRuleset", "Performance", "Statistics", "QueryOptimizer" ],
15+
"displayName": "Auto-Create Statistics should be on",
16+
"description": "The Query Optimizer determines whether an index is useful for a specific query by evaluating the stored statistics. If the statistics become out of date and significant changes have occurred against the underlying data, this can result in less than optimal query performance. In most cases, it's best to let SQL Server maintain the statistics. If you turn 'Auto Create Stats' and 'Auto Update Stats' off, then it is up to you to keep the statistics up-to-date somehow. Failure to do so will lead to poor query performance. Most applications should have these options ON.\n \n When the Auto Create statistics setting is ON, the Query Optimizer creates statistics on one or more columns of a table or an indexed view, as necessary, to improve query plans and query performance.",
17+
"message": "Turn Auto-Create Statistics option on to improve query performance.",
18+
"helpLink": "https://docs.microsoft.com/sql/relational-databases/statistics/statistics#CreateStatistics",
19+
"probes": [ "Custom_DatabaseConfiguration" ],
20+
"condition": "@is_auto_create_stats_on"
21+
},
22+
{
23+
"target": {
24+
"type": "Server",
25+
"platform": "/^(Windows|Linux)$/",
26+
"engineEdition": "OnPremises"
27+
},
28+
"id": "Custom_TF834",
29+
"itemType": "definition",
30+
"tags": [ "CustomRuleset", "TraceFlag", "Performance", "Memory", "ColumnStore" ],
31+
"displayName": "TF 834 enables large-page allocations",
32+
"description": "Trace Flag 834 causes the server to use large-page memory (LPM) model for the buffer pool allocations. Consider enabling TF 834 if you have a server that has a lot of memory, particularly for an analytical or data warehousing workload. Trace flag 834 is NOT recommended on SQL Server instances that use columnstore indexes.",
33+
"message": "Enable trace flag 834 to use large-page allocations to improve analytical and data warehousing workloads.",
34+
"helpLink": "https://support.microsoft.com/help/4465518",
35+
"level": "Information",
36+
"probes": [ "Custom_EnabledGlobalTraceFlags" ],
37+
"condition": {
38+
"in": [ 834, "@TraceFlag" ]
39+
}
40+
},
41+
{
42+
"id": "Custom_TF834",
43+
"itemType": "override",
44+
"targetFilter": {
45+
"version": "(,11.0)"
46+
},
47+
"description": "Trace Flag 834 causes the server to use large-page memory (LPM) model for the buffer pool allocations. Consider enabling TF 834 if you have a server that has a lot of memory, particularly for an analytical or data warehousing workload.",
48+
"message": "Consider enabling trace flag 834 to use large-page allocations to improve analytical and data warehousing workloads.",
49+
"helpLink": "https://support.microsoft.com/help/2964518"
50+
}
51+
],
52+
"probes":{
53+
"Custom_DatabaseConfiguration": [
54+
{
55+
"type": "SQL",
56+
"target": {
57+
"type": "Database",
58+
"version": "(,12.0)",
59+
"platform": "/^(Windows|Linux)$/",
60+
"engineEdition": "OnPremises, ManagedInstance"
61+
},
62+
"implementation": {
63+
"query": "SELECT db.is_auto_create_stats_on, db.is_auto_update_stats_on, 0 AS query_store_state, db.collation_name, (SELECT collation_name FROM master.sys.databases (NOLOCK) WHERE database_id = 1) AS master_collation, db.is_auto_close_on, db.is_auto_shrink_on, db.page_verify_option, db.is_db_chaining_on, NULL AS is_auto_create_stats_incremental_on, db.is_trustworthy_on, db.is_parameterization_forced FROM [sys].[databases] (NOLOCK) AS db WHERE db.[name]=@TargetName"
64+
}
65+
},
66+
{
67+
"type": "SQL",
68+
"target": {
69+
"type": "Database",
70+
"version": "[12.0, 13.0)",
71+
"platform": "/^(Windows|Linux)$/",
72+
"engineEdition": "OnPremises, ManagedInstance"
73+
},
74+
"implementation": {
75+
"query": "SELECT db.is_auto_create_stats_on, db.is_auto_update_stats_on, 0 AS query_store_state, db.collation_name, (SELECT collation_name FROM master.sys.databases (NOLOCK) WHERE database_id = 1) AS master_collation, db.is_auto_close_on, db.is_auto_shrink_on, db.page_verify_option, db.is_db_chaining_on, db.is_auto_create_stats_incremental_on, db.is_trustworthy_on, db.is_parameterization_forced FROM [sys].[databases] (NOLOCK) AS db WHERE db.[name]=@TargetName"
76+
}
77+
},
78+
{
79+
"type": "SQL",
80+
"target": {
81+
"type": "Database",
82+
"version": "[13.0,)",
83+
"platform": "/^(Windows|Linux)$/",
84+
"engineEdition": "OnPremises, ManagedInstance"
85+
},
86+
"implementation": {
87+
"useDatabase": true,
88+
"query": "SELECT db.is_auto_create_stats_on, db.is_auto_update_stats_on, (SELECT CAST(actual_state AS DECIMAL) FROM [sys].[database_query_store_options]) AS query_store_state, db.collation_name, (SELECT collation_name FROM master.sys.databases (NOLOCK) WHERE database_id = 1) AS master_collation, db.is_auto_close_on, db.is_auto_shrink_on, db.page_verify_option, db.is_db_chaining_on, db.is_auto_create_stats_incremental_on, db.is_trustworthy_on, db.is_parameterization_forced FROM [sys].[databases] (NOLOCK) AS db WHERE db.[name]=@TargetName"
89+
}
90+
}
91+
],
92+
"Custom_EnabledGlobalTraceFlags": [
93+
{
94+
"type": "SQL",
95+
"target": {
96+
"type": "Server",
97+
"engineEdition": "OnPremises, ManagedInstance"
98+
},
99+
"implementation": {
100+
"query": "DECLARE @tracestatus TABLE (TraceFlag NVARCHAR(40), [Status] tinyint, [Global] tinyint, [Session] tinyint); INSERT INTO @tracestatus EXEC ('DBCC TRACESTATUS WITH NO_INFOMSGS'); IF NOT EXISTS(SELECT * FROM @tracestatus WHERE Global=1) SELECT 0 AS [TraceFlag], 0 AS [Status] ELSE SELECT [TraceFlag], [Status] FROM @tracestatus WHERE Global=1",
101+
"transform": {
102+
"type": "aggregate",
103+
"map": {
104+
"TraceFlag": "array"
105+
}
106+
}
107+
}
108+
}
109+
]
110+
111+
}
112+
}

0 commit comments

Comments
 (0)