Skip to content

Commit 9a9a6b0

Browse files
authored
Merge pull request #664 from alexprotsenko/master
[SQL Asmnt] Updates to SQL Asmnt samples for GA
2 parents 392004f + aa540ec commit 9a9a6b0

5 files changed

Lines changed: 2553 additions & 1397 deletions

File tree

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
{
2-
"version": "0.2",
3-
"name": "Overrides for Default Ruleset",
4-
"checks":[
5-
{
6-
"id": "AutoCreateStats",
7-
"enabled": false
8-
},
9-
{
10-
"select": ["TraceFlag"],
11-
"enabled": false
12-
}
13-
]
14-
}
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "0.2",
4+
"name": "Custom Overrides",
5+
"rules":[
6+
{
7+
"id": "LatestCU",
8+
"itemType": "override",
9+
"enabled": false
10+
},
11+
{
12+
"id": ["TraceFlag"],
13+
"itemType": "override",
14+
"enabled": false
15+
},
16+
{
17+
"id": ["DefaultRuleset"],
18+
"itemType": "override",
19+
"targetFilter": {
20+
"type": "Database",
21+
"name": "/^(DBName1|DBName2)$/"
22+
},
23+
"enabled": false
24+
}
25+
]
26+
}
Lines changed: 116 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,116 @@
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+
"version": "[13.0,)",
10+
"platform": "/^(Windows|Linux)$/",
11+
"engineEdition": "OnPremises, ManagedInstance",
12+
"name": { "not": "/^(master|tempdb|model)$/" }
13+
},
14+
"id": "QueryStoreOn",
15+
"itemType": "definition",
16+
"tags": [ "CustomRuleset", "Performance", "QueryStore", "Statistics" ],
17+
"displayName": "Query Store should be active",
18+
"description": "The 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. While Query Store collects queries, execution plans and statistics, its size in the database grows until this limit is reached. When that happens, Query Store automatically changes the operation mode to read-only and stops collecting new data, which means that your performance analysis is no longer accurate.",
19+
"message": "Make sure Query Store actual operation mode is 'Read Write' to keep your performance analysis accurate",
20+
"helpLink": "https://docs.microsoft.com/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store",
21+
"probes": [ "Custom_DatabaseConfiguration" ],
22+
"condition": {
23+
"equal": [ "@query_store_state", 2 ]
24+
}
25+
},
26+
{
27+
"target": {
28+
"type": "Server",
29+
"platform": "/^(Windows|Linux)$/",
30+
"engineEdition": "OnPremises"
31+
},
32+
"id": "Custom_TF834",
33+
"itemType": "definition",
34+
"tags": [ "CustomRuleset", "TraceFlag", "Performance", "Memory", "ColumnStore" ],
35+
"displayName": "TF 834 enables large-page allocations",
36+
"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.",
37+
"message": "Enable trace flag 834 to use large-page allocations to improve analytical and data warehousing workloads.",
38+
"helpLink": "https://support.microsoft.com/help/4465518",
39+
"level": "Information",
40+
"probes": [ "Custom_EnabledGlobalTraceFlags" ],
41+
"condition": {
42+
"in": [ 834, "@TraceFlag" ]
43+
}
44+
},
45+
{
46+
"id": "Custom_TF834",
47+
"itemType": "override",
48+
"targetFilter": {
49+
"version": "(,11.0)"
50+
},
51+
"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.",
52+
"message": "Consider enabling trace flag 834 to use large-page allocations to improve analytical and data warehousing workloads.",
53+
"helpLink": "https://support.microsoft.com/help/2964518"
54+
}
55+
],
56+
"probes":{
57+
"Custom_DatabaseConfiguration": [
58+
{
59+
"type": "SQL",
60+
"target": {
61+
"type": "Database",
62+
"version": "(,12.0)",
63+
"platform": "/^(Windows|Linux)$/",
64+
"engineEdition": "OnPremises, ManagedInstance"
65+
},
66+
"implementation": {
67+
"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"
68+
}
69+
},
70+
{
71+
"type": "SQL",
72+
"target": {
73+
"type": "Database",
74+
"version": "[12.0, 13.0)",
75+
"platform": "/^(Windows|Linux)$/",
76+
"engineEdition": "OnPremises, ManagedInstance"
77+
},
78+
"implementation": {
79+
"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"
80+
}
81+
},
82+
{
83+
"type": "SQL",
84+
"target": {
85+
"type": "Database",
86+
"version": "[13.0,)",
87+
"platform": "/^(Windows|Linux)$/",
88+
"engineEdition": "OnPremises, ManagedInstance"
89+
},
90+
"implementation": {
91+
"useDatabase": true,
92+
"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"
93+
}
94+
}
95+
],
96+
"Custom_EnabledGlobalTraceFlags": [
97+
{
98+
"type": "SQL",
99+
"target": {
100+
"type": "Server",
101+
"engineEdition": "OnPremises, ManagedInstance"
102+
},
103+
"implementation": {
104+
"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",
105+
"transform": {
106+
"type": "aggregate",
107+
"map": {
108+
"TraceFlag": "array"
109+
}
110+
}
111+
}
112+
}
113+
]
114+
115+
}
116+
}
Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
# SQL Assessment API Quick Start Guide
2-
3-
Assess your SQL Server configuration for best practices in 2 simple steps.
4-
5-
6-
### 1. Setup
7-
8-
You just need to install PowerShell SqlServer module using the following command. Get-Module will show you the version you have installed. 21.2.18179 is the latest version and CTP2 for SQL Assessment API.
9-
10-
```PowerShell
11-
Install-Module -Name SqlServer -AllowClobber -Force
12-
Get-Module
13-
```
14-
15-
### 2. Invoke an assessment
16-
17-
This command runs an assessment against your local SQL Server instance.
18-
19-
```PowerShell
20-
Get-SqlInstance -ServerInstance 'localhost' | Invoke-SqlAssessment
21-
```
22-
23-
Sample result:
24-
![Sample Result](images/SQLAssessmentPSResult.png)
25-
26-
You will see in the results that each rule has some properties (not the full list):
27-
28-
- Severity (info, warning, critical)
29-
- Message property explains the recommendation but if you need more info, there is a HelpLink property that points at documentation on the subject.
30-
- Origin shows which ruleset and version the recommendation is coming from
31-
32-
See config.json for a full list of rules and properties.
33-
34-
If you want to get recommendations for all databases on the local instance, you can run this command.
35-
36-
```PowerShell
37-
Get-SqlDatabase -ServerInstance 'localhost' | Invoke-SqlAssessment
38-
```
39-
40-
## Learn more about SQL Assessment API
41-
42-
To learn more about SQL Assessment API such as customizing and extending the ruleset, saving the results in a table, etc., please visit:
43-
44-
- Docs online page: https://docs.microsoft.com/sql/sql-assessment-api/sql-assessment-api-overview
45-
- GitHub repo: http://aka.ms/sql-assessment-api
46-
- SQL Assessment API Tutorial notebook: coming soon
1+
# SQL Assessment API Quick Start Guide
2+
3+
Assess your SQL Server configuration for best practices in 2 simple steps.
4+
5+
### 1. Setup
6+
7+
You just need to install [PowerShell SqlServer module](https://www.powershellgallery.com/packages/SqlServer) using the following command. Get-Module will show you the version you have installed. 21.1.18206 is the latest version and GA for SQL Assessment API.
8+
9+
```PowerShell
10+
Install-Module -Name SqlServer -AllowClobber -Force
11+
Get-Module
12+
```
13+
14+
### 2. Invoke an assessment
15+
16+
This command runs an assessment against your local SQL Server instance.
17+
18+
```PowerShell
19+
Get-SqlInstance -ServerInstance 'localhost' | Invoke-SqlAssessment
20+
```
21+
22+
Sample result:
23+
![Sample Result](images/SQLAssessmentPSResult.png)
24+
25+
You will see in the results that each rule has some properties (not the full list):
26+
27+
- Severity (info, warning, critical)
28+
- Message property explains the recommendation but if you need more info, there is a HelpLink property that points at documentation on the subject.
29+
- Origin shows which ruleset and version the recommendation is coming from
30+
31+
See [config.json](./config.json) for a full list of rules and properties.
32+
33+
If you want to get recommendations for all databases on the local instance, run this command.
34+
35+
```PowerShell
36+
Get-SqlDatabase -ServerInstance 'localhost' | Invoke-SqlAssessment
37+
```
38+
39+
## Learn more about SQL Assessment API
40+
41+
To learn more about SQL Assessment API such as customizing and extending the ruleset, saving the results in a table, etc., please visit:
42+
43+
- Docs online page: https://docs.microsoft.com/sql/sql-assessment-api/sql-assessment-api-overview
44+
- GitHub repo: http://aka.ms/sql-assessment-api
45+
- SQL Assessment API Tutorial notebook: coming soon

0 commit comments

Comments
 (0)