SQL Server Profiler   «Prev  Next»

Lesson 6 Extended Events and Sessions
Objective Run extended events and sessions

Run Extended Events Sessions in SQL Server

In modern SQL Server, performance and diagnostic monitoring is built around Extended Events (XE / XEvents). You do not “run traces” anymore—your operational workflow is to create an Extended Events session, start it, view data live or write results to a target (usually an .xel file), then stop and analyze the capture.

What you need before you start

Extended Events session lifecycle

Think of an XE session as a repeatable diagnostic instrument you define once and run when needed:

  1. Define the session (events + actions + predicates + targets + session options).
  2. Start the session (capture begins immediately).
  3. Observe live data (optional) while the session runs.
  4. Stop the session (capture ends; definition remains).
  5. Analyze the target output (.xel file in SSMS or via T-SQL).
  6. Drop the session if it was temporary.

Method A: Create and run a session in SSMS

1) Create the session (SSMS wizard)

  1. Open Object Explorer.
  2. Expand ManagementExtended EventsSessions.
  3. Right-click SessionsNew Session Wizard… (or New Session…).
  4. Name the session using a descriptive purpose (example: XE_SlowStatements or XE_Deadlocks).

2) Choose the events you want to capture

Select events that match your troubleshooting goal. Common starting points:

3) Add actions for context

Actions are the “who/where/what context” you attach to the event stream: session id, database name, application name, user name, SQL text, and so on. Start minimal—only add what you will actually use to filter and analyze.

4) Apply predicates (filters)

Filters reduce overhead and noise. For example, only capture duration ≥ 1 second, or only capture activity in one database. Aggressive filtering is a best practice for production troubleshooting.

5) Choose a target

6) Start the session and view Live Data

  1. Right-click the session → Start Session.
  2. Right-click again → Watch Live Data to see events as they arrive.
  3. When finished, right-click → Stop Session.

Method B: Create, start, stop, and analyze a session with T-SQL

Scripting is ideal when you want repeatability (runbooks, incident response, jobs, and consistent production workflows). The example below captures slow statements to an event_file target with rollover, causality tracking, and a time limit.

-- Create a session to capture slow statements with useful context
CREATE EVENT SESSION [XE_SlowStatements] ON SERVER
ADD EVENT sqlserver.sql_statement_completed
(
  ACTION
  (
    sqlserver.session_id,
    sqlserver.database_name,
    sqlserver.client_app_name,
    sqlserver.username,
    sqlserver.sql_text,
    package0.event_sequence
  )
  WHERE
  (
    [duration] >= (1000000) -- 1 second (microseconds)
  )
)
ADD TARGET package0.event_file
(
  SET filename = N'C:\XE\XE_SlowStatements.xel',
      max_file_size = (50),
      max_rollover_files = (4)
)
WITH
(
  MAX_DISPATCH_LATENCY = 5 SECONDS,
  TRACK_CAUSALITY = ON,
  MAX_DURATION = 2 HOURS
);
GO

-- Start the session
ALTER EVENT SESSION [XE_SlowStatements] ON SERVER STATE = START;
GO

-- Stop the session when finished
ALTER EVENT SESSION [XE_SlowStatements] ON SERVER STATE = STOP;
GO

Analyze the captured output

If you used event_file, you can open the .xel file in SSMS, or query it with T-SQL for automation and reporting.

-- Read events from the XEL file (one row per event)
SELECT
  CAST(event_data AS xml) AS event_data_xml
FROM sys.fn_xe_file_target_read_file
(
  N'C:\XE\XE_SlowStatements*.xel',
  NULL, NULL, NULL
);

Best practice: treat sessions like controlled diagnostics, not permanent tracing

Legacy reference: Profiler images kept for historical context

The images below come from the legacy SQL Server Profiler era. They are preserved on this site to help you recognize older tooling in legacy documentation. In modern SQL Server, you will start/stop XE sessions (SSMS “Start Session / Stop Session” or ALTER EVENT SESSION) rather than “run traces.”

Trace Order
Legacy terminology. Profiler emphasized “trace order.” In Extended Events, use timestamp plus correlation (TRACK_CAUSALITY) and, when needed, package0.event_sequence to reconstruct deterministic ordering during analysis.

Running SQL Profiler
Legacy UI (SQL Server Profiler). In modern workflows, view XE data through SSMS Extended Events sessions and the Live Data viewer, or open/query .xel output from an event_file target.

start
Start concept (legacy icon). In Extended Events you start a session via SSMS (Start Session) or via: ALTER EVENT SESSION [name] ON SERVER STATE = START;

Operational caution: Extended Events is lightweight, but it is not “free.” Over-collecting events, capturing excessive actions, or running sessions without filters can still create overhead and large output files. Use a defined purpose, filter aggressively, and stop the session when the capture window ends.
In the next lesson, you will build on this workflow by interpreting session output fields and turning XE captures into repeatable tuning decisions.

SEMrush Software 6 SEMrush Banner 6