IT tutorials
 
Database
 

Creating Extended Events Sessions in SQL Server 2012 (part 4) - Counting the Number of Locks Acquired per Object , Creating Sessions Using T-SQL

12/19/2013 1:42:00 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Counting the Number of Locks Acquired per Object

The final example you’ll implement uses the histogram target to aggregate the number of locks acquired for objects in a user database as queries are executed. You might want to do this to help find locking hot spots in a database, but we’re using it here because it’s an easy way to demonstrate how the histogram target, and in this example the event filters, work.

The lock_acquired event provides all the information needed for this example, so you don’t need to use any global actions or additional event fields. Instead, because SQL Server itself has a lot of background locking activity from system processes occurring, you’ll use a filter to exclude the locking activity you’re not interested in. The configuration for this is shown in Figure 12.

FIGURE 12

image

If you are wondering where the filter values came from, the answer is a combination of known requirements and trial and error. One of the benefits of deploying an Extended Events session is that it’s easy to stop the session, reconfigure it, and restart it if it’s capturing too many or too few events (see the object_id filter setting shown in the screenshot). The database_id field was populated by executing the query select db_id(’PSDemo’).

With the filter configured, next you add the histogram target (see Figure 13). This requires configuring some properties but you can use values selected from drop-down lists. You can think of the “Base buckets on” option as being like the columns in a group by clause of a select statement.

FIGURE 13

image

With the session running, you can then execute the insert statement from the previous example to cause locks to be acquired in your sample database:

insert t1 (val1, val2) (select val1, val2 from t1)

This produces data in the histogram that looks something like what is shown in Figure 14.

FIGURE 14

image

If you are wondering what the object IDs refer to in the example database, 245575913 was the actual table t1, while 261575970 was the default constraint that was bound to the ID column of table t1.

Creating Sessions Using T-SQL

Extended Events has a very comprehensive set of T-SQL commands, which have deliberately not been covered in depth here. Unfortunately, their complexity has been one of the main reasons why people have not yet begun to use them, which is why this material has focused on using the SSMS interface.

However, if you want to start using the T-SQL Extended Events commands, the SSMS interface can help you get started by scripting out a session after you define it. You can do this using the Script button, which you are probably familiar with from other parts of SSMS; however, it’s shown in Figure 15.

FIGURE 15

image

For example, a session that captures all the logout events is shown here as a T-SQL create script:

CREATE EVENT SESSION [LogoutEvents] ON SERVER 
ADD EVENT sqlserver.logout(ACTION(sqlserver.client_app_name,
sqlserver.client_hostname,sqlserver.nt_username))
ADD TARGET package0.event_file(SET filename=N'C:\XELogs\LogoutEvents.xel')
WITH (STARTUP_STATE=ON)
GO
 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us