Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
SQL

SQL Server: Fix an Extended Events Session Filling Its Target File

- 02.12.26 - ErcanOPAK

🗄️ 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_files to 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_buffer target 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_sessions and 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.

— Database Engineer

Related posts:

SQL Server — LEFT JOIN + WHERE Turns Into INNER JOIN

SQL Server — LEFT JOIN + WHERE Turns Into INNER JOIN

SQL Execution Plan Reuse: Boost Query Performance with Plan Caching

SQL Execution Plan Reuse: Boost Query Performance with Plan Caching

SQL 'string_split()' function

SQL 'string_split()' function

Views: 0
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Git: Fix rerere Replaying a Resolution You Already Reverted
HTML5: Fix a Dialog Backdrop Blocking Clicks After Close

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 869 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com