🗄️ SQL Server: Fix an Extended Events Session Filling Its Target File
An Extended Events session writing to a file target with max_file_size set but no max_rollover_files limit (or one left at its very high default) will keep creating new rollover files indefinitely as the current one fills up, rather than wrapping back around to overwrite older data the way a ring buffer target does — and a session left running long-term for ongoing diagnostics, capturing a reasonably chatty event like sql_statement_completed on a busy server, can quietly consume tens or hundreds of gigabytes of disk space over weeks without anyone noticing, right up until the drive hosting those files actually fills up and takes the whole instance down with an out-of-space error that has nothing obviously to do with the diagnostic session that caused it.
🔎 The Problem
CREATE EVENT SESSION [ongoing_diag] ON SERVER
ADD EVENT sqlserver.sql_statement_completed
ADD TARGET package0.event_file
(
SET filename = N'D:\XEvents\ongoing_diag.xel',
max_file_size = 500 -- MB per file
-- no max_rollover_files set - defaults effectively unbounded,
-- so a new file gets created every time the current one hits 500MB
-- and NONE of them ever get deleted or overwritten automatically
)
WITH (STARTUP_STATE = ON);
-- Three weeks later:
-- D:\XEvents\ has 240+ rolled-over .xel files, ~120 GB total,
-- and the data drive just hit 100% full
âś… Fix: Bound the Session’s Total Disk Footprint Explicitly
- Set
max_rollover_filesto a concrete number when creating any long-running file-target session, so the session caps its total disk usage (file size times rollover count) instead of growing without limit — a ring-buffer-style bound is exactly what this setting exists to provide for file targets. - Prefer the
ring_buffertarget over a file target for any session meant to run indefinitely for general monitoring rather than a specific, time-boxed investigation — a ring buffer target has a fixed memory ceiling by design and never touches disk at all, which is usually what “keep this running just in case” monitoring actually needs. - Audit
sys.dm_xe_sessionsand the corresponding target file folders periodically (or alert on the data drive’s free space directly) for any session that’s been running longer than its original intended diagnostic window, since a session created to debug one specific incident is easy to forget about once that incident is resolved.
🚨 Why This Is Dangerous
- A data drive filling up from forgotten diagnostic files doesn’t announce itself as an Extended Events problem — it surfaces as the instance itself failing to write to tempdb, to the transaction log, or to the data files, producing a full outage whose root cause (a monitoring session nobody remembered was still running) can take far longer to trace than the actual fix.
A diagnostic session you forgot to stop doesn’t stop needing somewhere to write its data — it just keeps writing, quietly, until the drive it’s writing to runs out of room for everything else the instance needs.



