Search Results for: extended events

T-SQL Tuesday #166: Why Not Extended Events?

With 165 T-SQL Tuesday events, two, just two, this one, T-SQL Tuesday #166, and another one back in 2018 or 2019 (I forget and I'm far too lazy to go look) have been on Extended Events. At conferences I'm frequently the only one doing sessions on Extended Events (although, sometimes, Erin Stellato is there, presenting a better session than mine). I did a session at SQL Konferenz in Germany earlier this week on Extended Events. Hanging out in the hallway at the event (which was great by the way), I was talking with some consultants. Here's their paraphrased (probably badly) story: "I was working with an organization just a few weeks back. They found that Trace was truncating the text on some queries they were trying to track. I asked…
Read More

T-SQL Tuesday #166: Extended Events

When I was put on the list to host September's T-SQL Tuesday, well, I forgot to put it in my calendar. So I'm late (and in the doghouse with Steve). Because of this, I'm going to bend the rules a little (sorry Steve) and give you a few days to get your posts together. In theory, they're all due tomorrow, Tuesday, September 12. However, let's say they're all due by the end of the day on Thursday, September 14th. My apologies for being tardy. I'll still post a roundup on Friday. So, what's the topic for T-SQL Tuesday. Well, it's in the title, Extended Events. Let's talk about it. Why Extended Events? As anyone who has read my blog or books, or seen me speak, you'll know that I've got…
Read More

Extended Events for Anything but Query Tuning: bulk_insert_usage

Wouldn't it be great to be able to directly monitor specific behaviors within SQL Server, like, oh, I don't know, knowing exactly when, and how, someone is using BULK INSERT? Well, you can, thanks to Extended Events through the bulk_insert_usage event. Bulk_insert_usage The BULK INSERT command is extremely useful within SQL Server. It's a way to move data into the database and provide some formatting on the way, efficiently, all through T-SQL. Hard to argue with the utility. Obviously, if you're doing traditional data collection through Trace or Extended Events, you'll see BULK INSERT commands within the T-SQL. However, Extended Events provides a specific event that tracks just the behavior of BULK INSERT: bulk_insert_usage. Documentation on this is somewhat sparse. Some of the best is from a standard source, Jason…
Read More

Extended Events for Anything but Query Tuning: Object Changes

I hear this one all the time: How do I find out who implemented object changes? I also get: Can I see the query that caused object changes? Let's take a look at how you might audit who is doing what and how to your databases. Object Changes in Extended Events If you open up the New Session window for Extended Events in SSMS, the easy way to track down events is to simply type into the box. Here, we care about capturing object changes, so I'm going to simply type object, then scroll a bit: There we are object_altered, object_created and object_deleted. These are the same events that you would see in Trace. Let's use the GUI and take a quick look at what fields they capture: That's in…
Read More

Extended Events for Anything But Query Tuning: xml_deadlock_report_filtered

One of my favorite little bits of information about Extended Events is the fact that everyone running a full instance of SQL Server has deadlock information available to them, even if they never enabled Trace Flag 1222 through the system_health session. That captures the xml_deadlock_report which has the full deadlock graph. However, what if you want to capture deadlock info, but, you're dealing the GDPR, and transmitting query values could be problematic? Enter xml_deadlock_report_filtered. xml_deadlock_report_filtered If you do a search for this event, you're not going to find much. Doesn't seem like anyone, including Microsoft, has bothered to document it. This is not going to be a comprehensive definition for all things xml_deadlock_report_filtered. However, I can show you why you might want to use it. This is a port of…
Read More

Extended Events for Anything But Query Tuning: Unique Constraint Violations

Most of the time when I talk about or demo Extended Events, I spend more time talking about query tuning (I have a problem). However, there are tons of things that you can do with Extended Events. Here's a little one that came up, auditing unique constraint violations. Unique Constraint Violations Whether we're talking a primary key or just a constraint, the error you get is number 2627 when you attempt to add a non-unique value. So, the code for a simple way to track this in Extended Events would look like this: CREATE EVENT SESSION [UniqueConstraintViolation] ON SERVER ADD EVENT sqlserver.error_reported (WHERE ([error_number] = (2627))); That's it. That's all you need. Probably, it'd be a good idea to output this to a file (that's usually what I do). However,…
Read More

Extended Events in AWS RDS

For the longest time, we didn't have one of the most useful tools for monitoring SQL Server behavior, but I just found out that, indeed, you can use Extended Events in AWS RDS. I'm not waiting around. Let's see it in action. Setup For Extended Events in AWS RDS AWS has posted the documentation on what you have to do in order to enable the collection of Extended Events within RDS. Normallly, I'd follow along with the documentation. However, I'm going to approach this like I knew that Extended Events support was there, but I wasn't aware of the docs. So, I'm starting in SSMS and I'm just going to try plugging in the Extended Events GUI to see what happens. Further, I'm going to use the simplest method for…
Read More

Extended Events Session Properties

I like Extended Events and I regularly use the Session Properties window to create and explore sessions. I'm in the window all the time, noting it's quirks & odd behaviors, even as it helps me get stuff done. However, found a new one. Let me tell you about just a few of them. Session Properties Window When you open the Extended Events session properties window for an existing session, in SSMS 18.1, it should look something like this: See the problem? Well, that is the problem. Here, look after I resize it: There it is. At the bottom. By default, the window isn't sized correctly so you see everything. In fact, I'm in the habit of maximizing the window, just because it makes it easier to work with. However, I…
Read More

Filtering Extended Events Using Actions

Did you know, you can use Actions to Filter Extended Events? Well, you can. Filtering is one of the greatest ways in which Extended Events differentiates itself from other mechanisms of gathering information about the behavior of SQL Server. You can put Actions to work in your filtering. Best of all, the Actions don't have to be collected in order to put them to work filtering your Extend Events. Using Actions To Filter Extended Events Actions, also called Global Fields, are additional bits of data that you can add to a given Event when you're setting up an Extended Events Session. They are programmatic additions to the Event, as described here. Think of them sort of like triggers. In practice, adding an Action, database_name, to an Event, like the rpc_completed…
Read More

Using Extended Events Live Data With Azure

In my last post I showed some shortcomings of Extended Events, however, it is possible to use Live Data with Azure. Let's explore exactly how that works. To get started, you'll need to follow the directions here to get set up with Azure Storage as the output target of your Extended Events session within your Azure SQL Database. There is a little bit of prep work, but it's all laid out in Microsoft's document. I found the Powershell to be a bit sketchy, but it shows you what's needed. The T-SQL just works. Live Data With Azure Once you've created an Extended Events Session that is output to Azure Storage, you've done most of the work. The trick is really simple. Get the Azure Storage account set up with a…
Read More