Saturday, April 9, 2022

Tips & Tricks #2: SQL Server Profiler (xEvents) for Azure SQL DB

The SQL Server Profiler using SQL Server Management Studio (SSMS) currently support Azure SQL Manage Instance and SQL Server platforms and does not support Azure SQL DB platform, so as a workaround we can use SQL Server Profiler extension for Azure Data Studio (ADS).

 

"The SQL Server Profiler extension provides a simple SQL Server tracing solution similar to SQL Server Management Studio (SSMS) Profiler except built using Extended Events. SQL Server Profiler is very easy to use and has good default values for the most common tracing configurations. The UX is optimized for browsing through events and viewing the associated Transact-SQL (T-SQL) text. The SQL Server Profiler for Azure Data Studio also assumes good default values for collecting T-SQL execution activities with an easy to use UX. This extension is currently in preview." More information can be found here.

 

In this article we will cover the below contents:

  • How to use the SQL Server Profiler extension for Azure SQL DB.
  • How to export the output session into an XML-file (.xml).
  • How to export the output session into an XEL-file (.xel) and store it into an Azure Storage Account.

Prerequisites:

How to use the SQL Server Profiler extension for Azure SQL DB:

  1. Open ADS and click on Extensions from the left-side then search for SQL Profiler For Azure Data Studio and finally click on Install, please have look at the below snapshot:

    Mustafa_Ashour_0-1622234037648.jpeg

  2. Click on Connections (Left-side), then click on Add Connection, please have a look at the below snapshot:

    Mustafa_Ashour_1-1622234037653.png
  3. In the add new connection dialog, fill in your Azure SQL Server information and select the database, please have a look at the below snapshot:

    Mustafa_Ashour_2-1622234037656.jpeg

  4. In the create new firewall rule, click on reenter your credentials, please have a look at the below snapshot:

    Mustafa_Ashour_3-1622234037658.jpeg

  5. After entering your credentials and back to the firewall rule dialog, select add my client IP and then click OK, please have a look at the below snapshot:

    Mustafa_Ashour_4-1622234037659.jpeg

  6. After that you will be back to the connection dialog, then select your database and click connect, please have a look at the below snapshot:

    Mustafa_Ashour_5-1622234037661.jpeg

  7. After establishing a connection, right-click on your Azure SQL database and select Launch profiler (Alt+P), please have a look at the below snapshot:

    Mustafa_Ashour_6-1622234037663.jpeg

  8. From Start New Profiler Session dialog, enter session name and click on Start, please have a look at the below snapshot:

    Mustafa_Ashour_7-1622234037665.jpeg

  9. A profiler tab will appear with all the events that is currently running on the Azure SQL database, please have a look at the below snapshot:

    Mustafa_Ashour_8-1622234037666.jpeg

  10. Right-click on your Azure SQL database and select New Query, please have a look at the below snapshot:

    Mustafa_Ashour_9-1622234037668.jpeg

  11. Enter your specified query and click on Run, then click on the profiler tab and you will notice your query event is logged, please have a look at the below snapshot:

    Mustafa_Ashour_10-1622234037669.jpeg

     

How to export the output session into an XML-file (.xml):

  1. Open SSMS and connect to your Azure Database.
  2. Open Extended Events and select the session that you have created in Azure Data Studio.
  3. Right-click on the session buffer and select View Target Data.
  4. In the Session buffer tab (in the right-side) right-click and select Refresh (XML data will be created).
  5. Click on XML Data and save the new view tab as XML and please send it to me.

Please have a look at the following snapshots:

 

Mustafa_Ashour_0-1622370396287.jpeg

 

Mustafa_Ashour_1-1622370396295.jpeg

 

How to export the output session into an XEL-file (.xel) and store it into an Azure Storage Account:

  1. From SSMS, right-click on your session and select properties
  2. From session properties, select Data Storage to and enter your Azure Storage Account to save the file as “.xel” as shown in the below image and click OK.
  3. From SSMS, right-click on your session and select start session (if not running already).
  4. After you finish from capturing events, open your storage account where you saved your “.xel” file.
  5. Download it into your local machine then open it using SSMS and follow this document to export the results into table to be able to filter the results as per your needs.

 

Mustafa_Ashour_2-1622370633970.png

 

More information can be found in the below document:

 

Posted at https://sl.advdat.com/3rgP30rhttps://sl.advdat.com/3rgP30r