Lesson Learned #195: Performance Best Practices for Azure SQL Database and Managed Instance.

Published Apr 06 2022 10:22 AM 2,742 Views

We usually work on performance issues that following the best practices might be resolved following them. In this article we would like to share a PowerShell Script that checks an example best practices for Azure SQL Database and Managed Instance.

 

We would like to suggest this PowerShell script that you could find out in this URL that contains initial checks we are facing a performance issue. This PowerShell Script is covering the following best practices:

 

  1. Check if we have any automatic tuning recomendations . Based on the results of the execution  of sys.dm_db_tuning_recommendations DMV informs if your database has any recomendations to apply in your database based on the workload analysis done by the SQL Server engine. 
  2. Check if we have have statistics that are out-of-dated Based on the results of the execution of sys.stats and sys.dm_db_stats_properties DMVs inform if any statistics, automatic , user created or associated with an index has the following conditions: If the rows sample is different than the number of rows (this situation may be indicated that the statistics has been updated automatic by SQL Server using a sample or if the statistics has been update more than 15 days ago. 
  3. Check if you have any TSQL that was cancelled or aborted. For example, after expiring of execution command timeout. This check is based on QDS DVM call sys.query_store_runtime_stats.
  4. Check if you have missing indexes. Based on the results of the execution of sys.dm_db_missing_index_xxx informs if you have any missing indexes that helps you to improve the execution of your query. 
  5. Check the setting value of MAXDOP. Based on the results of the sys.database_scoped_configurations DMV check if the value of MAXDOP is 0. 
  6. Check the fragmentation of the indexes. Based on the results of sys.dm_db_index_physical_stats DMV check if the fragmentation of the indexes is more than 50 percent. 

 

Basically, once you have download this PowerShell script, you need to provide the details of your server, database, user, password and destination folder. You could fill up directly these parameters in the PowerShell script if you need to perform more time this process. This PowerShell script only will ask those parameters if they are missing. Also, you could specify as a command line. 

 

Once the process is executed, this PowerShell script will save a file called PerfChecker.Log in the destination folder chosen. In every execution this file will be deleted and created a new one. 

 

This project is public and all the contributions to make more accesible, easy and effective will be very welcome. 

 

Enjoy!

 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-3277878%22%20slang%3D%22en-US%22%3ELesson%20Learned%20%23195%3A%20Performance%20Best%20Practices%20for%20Azure%20SQL%20Database%20and%20Managed%20Instance.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3277878%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20usually%20work%20on%20performance%20issues%20that%20following%20the%20best%20practices%20might%20be%20resolved%20following%20them.%20In%20this%20article%20we%20would%20like%20to%20share%20a%20PowerShell%20Script%20that%20checks%20an%20example%20best%20practices%20for%20Azure%20SQL%20Database%20and%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20would%20like%20to%20suggest%20this%20PowerShell%20script%20that%20you%20could%20find%20out%20in%20this%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FJMNetwalker%2FPerfCollector%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EURL%3C%2FA%3E%26nbsp%3Bthat%20contains%20initial%20checks%20we%20are%20facing%20a%20performance%20issue.%20This%20PowerShell%20Script%20is%20covering%20the%20following%20best%20practices%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20we%20have%20any%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-sql%2Fdatabase%2Fautomatic-tuning-overview%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Eautomatic%20tuning%20recomendations%3C%2FA%3E%3C%2FSTRONG%3E%26nbsp%3B.%20Based%20on%20the%20results%20of%20the%20execution%26nbsp%3B%20of%26nbsp%3Bsys.dm_db_tuning_recommendations%20DMV%20informs%20if%20your%20database%20has%20any%20recomendations%20to%20apply%20in%20your%20database%20based%20on%20the%20workload%20analysis%20done%20by%20the%20SQL%20Server%20engine.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20we%20have%20have%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fupdate-statistics-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Estatistics%20that%20are%20out-of-dated%3C%2FA%3E%3C%2FSTRONG%3E%26nbsp%3BBased%20on%20the%20results%20of%20the%20execution%20of%20sys.stats%20and%20sys.dm_db_stats_properties%20DMVs%20inform%20if%20any%20statistics%2C%20automatic%20%2C%20user%20created%20or%20associated%20with%20an%20index%20has%20the%20following%20conditions%3A%20If%20the%20rows%20sample%20is%20different%20than%20the%20number%20of%20rows%20(this%20situation%20may%20be%20indicated%20that%20the%20statistics%20has%20been%20updated%20automatic%20by%20SQL%20Server%20using%20a%20sample%20or%20if%20the%20statistics%20has%20been%20update%20more%20than%2015%20days%20ago.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20you%20have%20any%20TSQL%20that%20was%20cancelled%20or%20aborted.%3C%2FSTRONG%3E%20For%20example%2C%20after%20expiring%20of%20execution%20command%20timeout.%20This%20check%20is%20based%20on%20QDS%20DVM%20call%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-catalog-views%2Fsys-query-store-runtime-stats-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.query_store_runtime_stats%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20you%20have%20missing%20indexes.%3C%2FSTRONG%3E%20Based%20on%20the%20results%20of%20the%20execution%20of%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-db-missing-index-groups-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_db_missing_index_xxx%3C%2FA%3E%20informs%20if%20you%20have%20any%20missing%20indexes%20that%20helps%20you%20to%20improve%20the%20execution%20of%20your%20query.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20the%20setting%20value%20of%20MAXDOP.%3C%2FSTRONG%3E%20Based%20on%20the%20results%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-catalog-views%2Fsys-database-scoped-configurations-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.database_scoped_configurations%3C%2FA%3E%20DMV%20check%20if%20the%20value%20of%20MAXDOP%20is%200.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20the%20fragmentation%20of%20the%20indexes.%3C%2FSTRONG%3E%20Based%20on%20the%20results%20of%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-db-index-physical-stats-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_db_index_physical_stats%3C%2FA%3E%20DMV%20check%20if%20the%20fragmentation%20of%20the%20indexes%20is%20more%20than%2050%20percent.%26nbsp%3B%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBasically%2C%20once%20you%20have%20download%20this%20PowerShell%20script%2C%20you%20need%20to%20provide%20the%20details%20of%20your%20server%2C%20database%2C%20user%2C%20password%20and%20destination%20folder.%20You%20could%20fill%20up%20directly%20these%20parameters%20in%20the%20PowerShell%20script%20if%20you%20need%20to%20perform%20more%20time%20this%20process.%20This%20PowerShell%20script%20only%20will%20ask%20those%20parameters%20if%20they%20are%20missing.%20Also%2C%20you%20could%20specify%20as%20a%20command%20line.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20the%20process%20is%20executed%2C%20this%20PowerShell%20script%20will%20save%20a%20file%20called%26nbsp%3B%3CSTRONG%3EPerfChecker.Log%3C%2FSTRONG%3E%20in%20the%20destination%20folder%20chosen.%20In%20every%20execution%20this%20file%20will%20be%20deleted%20and%20created%20a%20new%20one.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FJMNetwalker%2FPerfCollector%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Eproject%3C%2FA%3E%20is%20public%20and%20all%20the%20contributions%20to%20make%20more%20accesible%2C%20easy%20and%20effective%20will%20be%20very%20welcome.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEnjoy!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3277878%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20usually%20work%20on%20performance%20issues%20that%20following%20the%20best%20practices%20might%20be%20resolved%20following%20them.%20In%20this%20article%20we%20would%20like%20to%20share%20a%20PowerShell%20Script%20that%20checks%20an%20example%20best%20practices%20for%20Azure%20SQL%20Database%20and%20Managed%20Instance.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Version history
Last update:
‎Apr 06 2022 10:56 AM
Updated by: