Crash Course: SQL Server Extended Events

I’ve previously written about SQL Server Profiler and its use in diagnosing problematic T-SQL queries, stored procedures, and application behaviours. Although the SQL Server Profiler is very much the trusted tool for doing so it’s actually marked as deprecated by Microsoft. This unfortunately means that it will be removed in a future version of SQL Server.

In place of Profiler there is another feature called Extended Events (also referred to as XEvents or XEs). As Microsoft’s intended replacement for the Profiler it’s important to learn how this feature works in anticipation for a future release of SQL Server where Profiler is no longer available.

A key advantage of Extended Events is that they are less performance intensive than what SQL Server Profiler is and that they are designed to be left running to collect data. You’ll also notice that Extended Event sessions are all done directly in SSMS rather than launching a separate tool. As sessions are stored as objects within the SQL Server instance other DBAs can also make use of them.

Let’s work through a simple Extended Event session that will capture SQL queries being made in an AdventureWorks2022 test database.

Note: the following example was done on SQL Server 2022 CU17 running on Windows Server 2022 update 2025-01. SQL Server Management Studio 20.2 was used

Step 1: Launch SSMS from the start menu, login to the required SQL Server instance. Once you are logged in goto Instance Name > Management > Extended Events

Step 2: Create a session by right clicking the Sessions folder and clicking New Session Wizard.

Step 3: Click Next to skip past the introduction.

Step 4: Give your XEvent Session a descriptive name. For this example I’ve just used Tutorial 01. Click Next to proceed.

SSMS: Session Properties

Step 5: Although there are some templates to choose from select Do not use a template and click Next.

SSMS: Templates

Step 6: This page now allows you to select events you want to track. Search for the following events and then double click each line to add to the list to the right. Click Next once you have them all:

  • sql_batch_starting
  • sql_batch_completed
  • sp_statement_starting
  • sp_statement_completed
SSMS: Events To Capture

Step 7: In the list of global events to track let’s select the following and then click Next:

  • database_name
  • process_id
  • sql_text
  • username
SSMS: Capture Global Fields

Step 8: For filters I’m going to add in a line to narrow down the XEvent to AdventureWorks2022 using the filter sqlserver.database_name. Click Next once set:

SSMS: Sesseion Event Filters

Step 9: Leave the data storage options unchecked for now. We’re only going to demo this XEvent so we aren’t interested in keeping the data. Click Next.

SSMS: XEvent Storage Options

Step 10: Review the summary and click Finish when you are satisfied with your selections.

SSMS: XEvent Summary

Step 11: As we’d like to make use of this XEvent straight away check both options on the Summary screen then click Close.

SSMS: XEvent Summary Screen

You will then go back into SSMS. Note that the event Tutorial 01 now appears under Instance Name > Management > Extended Events > Sessions in the object explorer and also that a new window for the session events is open.

SSMS: Finished XEvent

At this point make a simple select query on AdventureWorks2022. I did a lazy one just for demo:

SELECT * FROM [Person].[Address]

You’ll now see events tracking in the session event window:

SSMS: XEvent Query Window

What you’ve just done is a simple session event trace but you can use the steps above to further customise your XEvent to capture the information you require.

Conclusion

We’ve discussed what SQL Server Extended Events are, what the advantages are, and performed a tutorial to build a very basic XEvent on a demo database.

If you organisation needs assistance with SQL Server we are here to help. Digital Incite and Matter Ltd’s consultants are SQL Server trained, certified and experienced with a wide variety of business applications. Get in touch with us today to discuss your requirements.

Merry Christmas and a Happy New Year from Digital Incite and Matter Ltd!

This week – in place of our usual content – Digital Incite and Matter Ltd would like to wish you a Merry Christmas and a Happy New Year for 2025.

Christmas tree photo by Brett Sayles: https://www.pexels.com/photo/merry-christmas-sign-1656564/

We hope you have a pleasant and safe holiday. Thank you all for reading the blog and using our services in 2024.

Closed Dates

We’re not available on the following dates over the holidays as we’ll be spending time with friends and family:

  • Wednesday 25th December
  • Thursday 26th December
  • Wednesday 1st January

We’ll be back in full on Thursday 2nd January and look forward to working with you in the new year!

Supporting World Mental Health Day

Masks off. This week on October 10th 2024 is World Mental Health day. This year’s theme is very on point for professionals worldwide: “It is time to Prioritize Mental Health in the Workplace”.

According to the charity Mind statistically around 1 in 4 people in England will experience a mental health issue each year with specific demographics such as LGBTQIA+, Black or Black British people, Young Women and those with overlapping problems even more likely to report mental health problems.

Thankfully the conversation is moving on and the stigma around having mental health problems is being challenged. In a work setting it’s of critical importance to create a mental well-being supportive environment. Whether it’s additional support from colleagues, time off to seek help and treatment or reworking a job role everyone should be able to get help when they need it most.

I volunteer for Andy’s Man Club and they’re a great example of a group that’s worked hard to challenge the stigma and support men like me when life got challenging. For other groups that cater to your needs check out Hub of Hope for links to other groups.

Taking a Career Break

It’s been some time (over)thinking, (over)planning and (over)delaying but today marks the first day of my career break.

I have been working for Lake Financial Systems for the past 8 years as a Technical Consultant specialising in Microsoft SQL Server, Microsoft Windows Server and Microsoft Azure. I have now decided it’s time to move along by taking a short career break. Thank you all to the Lake team once again and all the best for the future.

Once the decompression phase is over I’m working on transforming this site into the full functioning business I always intended it to be. As a business we’ll be offering the best of support to all kinds of organisations with your data and infrastructure requirements. I shall still be blogging and next week plan to release a review of the new StarLabs Linux tablet Starlite MKV.

Until next time!

Merry Christmas and a Happy New Year!

If you’re reading this I’ve temporarily closed off SQL Server Management Studio for the year and I’m spending time with my family & friends.

I hope you are having a wonderful Christmas too and that Santa brought you all the things in the world you wished for or at least everything Santa could do with the SQL login privileges he had at the time.

Thank you for reading the blog and I look forward to writing more content into 2024.

Powered by Pasties

Last week I’ve been back at work after a week scoffing pasties down in Cornwall with the family. I had a Parkrun and a few sea swims in between too which has been great. I also gave myself time to finish reading Diana Nyad’s memoir Find a Way.

Diana was the first person to swim from Cuba to the United States. This incredible achievement over a distance of around 180km (110 miles) took 5 attempts, a lot of heartache and dedication to the dream.

I wanted to read this book after watching an interesting Ted Talk by Diana titled “Never, ever give up”. In the 15 minute appearance she talks about the challenges and motivation she found for taking on extreme distance swimming. Right at the end she calls to the crowd “find a way!”. Not only did I want to read her full story I wanted to find out who exactly Badass Bonnie was too!

I found Find a Way well worth the read and interesting as an open water swimmer. I would definitely recommend it to anyone whether a swimmer, sports fan or in need of some inspiration.

That is also to say that other than doing “catch up” not in the water that’s as much as I’ve done professionally following my return.

I’M STILL ALIVE!!!1!!ONE

I remembered this week that I’ve not posted here for a while so in the interest of (1) confirming I am alive, (2) making some fluff up to prevent the blog from looking “abandoned pending domain expiry” and (3) to get back in some kind of rhythm.

Honestly it’s been busy. Nobody wants to stand still and as we all work out what’s going to be the “new normal” there’s a lot of push for cloud, automation and remote connectivity. That means a lot of work to be done so less time to have a natter on the blog.

Hopefully I will have a new laptop to review pretty soon so watch out for that.

Lick Of Paint

Speaking to a lot of people right now everyone’s at the stage where they’ve not much to talk about seen as they can’t leave their homes and…you know…do interesting things. I am looking forward to being back swimming and for a pint at the pub (not together though).

In the meantime I put a fresh lick of paint on the blog. Enjoy.

There’s Not Much To Say!

(Well there is but you know what I mean.)

In the UK we have gone into Lockdown 3: The Winter Crisis so there’s not much Round Tabling, swimming or pubbing to be done until the COVID-19 virus is brought under control. Fortunately consultancy is back in full swing so the bills are getting paid.

Priority number one and two for 2021 will be to stay safe and get the vaccine respectively. As a child my parents would always tell me to play outside and avoid any drugs especially needles. In 2021 they’re telling me to stop inside and get a jab as soon as my turn comes up. How times change.

Over Twixmas I did try my hand at building a PiHole on a Raspberry Pi 3 Model B that has been lurking in my drawer but I scrapped it after a week. I felt the omission of DNS over HTTP/TLS by default is too important to overlook. I plan to build a WiFi 6 core network at my house sometime in 2021.

Meanwhile I’ve been discussing PC builds with some good friends of mine as we’re enjoying Cyberpunk 2077. I’m currently drawing up a parts list for my next custom build I’ve provisionally called Build-V. Yes that is indeed because it’s the 5th custom build I’m intending to put together and yes that’s where all that petrol money I’ve saved is going.