Creating Wait stats widget on Azure Data Studio for macOS

A couple of weeks ago, Microsoft released a new multi-platform tool called Azure Data Studio, this tool is the final version of SQL Operations Studio. If you are familiar to SQLOps, you probably recall that this tool 100% open source, and because of that you can customize the JSON code to do certain things the way it works best for you.

In my personal opinion, this is of the best features of Azure Data Studio are widgets. It gives the option to DBA’s or Database developers to create their own custom widgets to access SQL Server data using simple charts. I personally don’t like the very buggy reports from SSMS which take time to load and are not fully customizable … they are like a black box to me.

I decided to give it a try and create a custom widget of wait stats, because I use them everyday and also is one of the most common troubleshooting methodologies across SQL Server data professionals. If you are not familiar with wait stats, you should … it provides diagnostic information that can help to determine the root cause or symptom of a potential bottleneck in multiple areas like:

  • Locking \ blocking issues
  • CPU pressure
  • Memory pressure
  • Disk IO problems

In this post, I will walk you through the creation of a custom widget to display the top 5 wait stats from your system but first  you must have Azure Data Studio installed on your computer already. So in case you don’t please make yourself a favor and download the macOS version on this link.

From now on, I will assume you have Azure Data Studio installed also a working connection to a SQL Server instance. All the Azure Data Studio widgets uses a query file as a source, in this case I created a short version of world-famous Paul Randal’s (b|t) script to determine the wait stats for a SQL Server instance, you can download the modified script here from my GitHub repository.

This short version will show only the top five wait types from your system, I also I removed the links from Paul’s version where he explains each ignored wait type just to make the code easier to read but I strongly recommend you to check Paul Randal’s blog post to learn more about.

Download the script and move it to a known location rather than your Downloads folder, this will make things easier while creating the widget. A folder location like /Users/MyUser/Documents/wait_stats.sql would work.

Open the script with Azure Data Studio and execute it, then go to the results window look at the top right corner of this section and click on the Chart icon:

Once the chart is displayed in the screen, look for the chart options from the right panel and make the following changes:

  • Chart Type = horizontalBar
  • Data Direction = Vertical
  • Legend Position = none
  • X Axis Label = PERCENTAGE
  • Y Axis Label = WAIT TYPE

As you may noticed at this point, a nice horizontal bar type char is displayed on your screen, but this is just halfway now let’s move ahead and get the widget created. Click on the Create Insight button at the top of the RESULTS \ CHART grid to generate the JSON code for this chart.

Azure Data Studio will open a new windows with some JSON code, probably you noticed the way it is showed in the screen is not that readable. Don’t you worry, we can address the format problem just select all the JSON code using the ⌘ A (Command + A) shortcut then just run the Format document function of Azure Data Studio using the ⇧⌥ F (Shift + Alt + F) shortcut and voilà the code is now looking perfectly formatted:

Noticed that I have highlighted the name key, because the auto-generated code puts My-Widget as value by default in our case we want to call this widget something like Wait stats, also noticed the queryFile key value it points the location you saved the wait stats script at the beginning of this post.

Finally it’s time to add our custom Wait stats widget to Azure Data Studio, open the Azure Data Studio command palette using the ⌘⇧P (Command + Shift + P) and then write Preferences you will see a list of options displayed as a list choose Preferences: Open User Settings from the list.

In the Search Settings text box write dashboard.server.widgets then click on dashboard.server.widgets and select the Edit option:

The left panel will turn yellow in Edit mode, now look for the last bracket from the last widget on the last panel in my case the all-database-size-server-insight. Carefully add a comma symbol after the last bracket, then copy the JSON code from the other window and paste it. It should look something like this:

Then simply save the changes to the user settings using the ⌘S (Command + S) shortcut, close all the open windows. Re-connect to one of your SQL Server instances, right click then choose manage it will display the server dashboard now just look for the widget we just created.

I hope you find this tip useful, in case you want to grab a copy of the SQL and JSON file used in this post you can find it here.

Stay tuned for more DBA mastery tips!

Starting SSMS with a specific connection and script file

Have you ever wanted SSMS to start and automatically and establish a connection to your DBA \ hub server and have your daily routine queries already open ready to run?

Good news, that is totally possible. SSMS actually uses the SSMS.exe in the background which has multiple options such as connecting to a specific SQL Server instance and opening a file. All these options are accessible through a few very simple command line parameters, if you are familiar with SQLCmd these parameters will like be really similar to you.

Let’s explore the different options available through command line, open PowerShell or CMD and running the following command:

 ssms -help 

As you may noticed a pop-up window showed up displaying the multiple options as server name, database name, user password, file name, log name, etc..

Now that we know the parameters, let’s have fun with these parameters!! Do you remember what I just mentioned at the beginning of this post? Let’s do a test, let’s call SMS from PowerShell and ask it to open a connection to a specific server (MASTER01 in this case) loading a SQL script file which contains a daily script:

Click for fullscreen

Ok, but you know what let’s make this more interesting, because we know already SSMS.exe it’s an executable and we have all these cool parameters to play with let’s modify the existing SSMS shortcut this time we will make SSMS to load a solution containing multiple SQL script files:

Click for fullscreen

As you may noticed from animation, I just added a set of specific parameters to the existing text, to be specific this is what I just added:

-S master01 
-d master 

This modification will make SSMS to start not showing the traditional splash screen (because yes I want to save a second of my time), it also pre-loads a SQL Server solution which contains a collection of scripts I intents to run from my SQL Server central instance (master01). In case I choose the “master” database as default database to connect to but as you can figure out at this point all these options can be changed 🙂

So this is how you can set a specific configuration for SSMS to use every time you start this application, I consider this tip a very handy trick you can use to save yourself some time.

Stay tuned for more DBA mastery tips.

I will be speaking at SQL Saturday # 788 – Denver

I’m very thrilled to announce that I will be participating as speaker in Denver’s SQL Saturday that will take place on September 15th. This is a huge step for me as technical speaker, because it was just June when I participated in Denver’s SQL Server User Group speaking about Query Store and now I had the chance to participate on Denver’s SQL Server annual great event.

And it is a big deal because there will be very recognized people around like Bob Ward who is the keynote speaker of this year, there will be participation from Glenn Berry, Kellyn Pot’Vin-Gorman, Tracy Boggiano, Jess Borland, Jason Brimhall and more!

Here is a picture of me with Steve Jones and Glenn Berry from Denver’s 2017 SQL Saturday:

Steve Jones & Glenn Berry – Denver SQL Server Saturday 2017

At that time I have no idea I will make the list of speakers for the year 2018, which I’m very grateful and proud.

I will be speaking about how to perform a SQL Server Health Check, this session is about the importance of conducting regular health checks on SQL Server instances to ensure that they are currently healthy, and continue to remain healthy.

This event will take place at University of Denver – Sturm Hall, 2040 S Race St, Denver, Colorado, 80210, United States.

Please remember as any SQL Saturday event you can register and attend for free, it just a matter to sign up here.

Looking forward to see you there!!!