Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear SQL Server Extended Events Event File

How to clear SQL Server extended events that are stored in a file?

Background

Where are the files for SQL Server Extended Events Event File target stored?

I want to delete months worth of log files; but SQL Server doesn't tell me where the files are:

enter image description here

I would follow the advice on Microsoft's SQL Server forums:

Clear events in file target?

Simply stop the session and delete .xel file if it’s no longer required.

Attempt#3

I tried doing the single most obvious thing that any user interface designer worth their salt would have created from the beginning: Right-click the event file target, and select:

  • Clear
  • Delete
  • Purge
  • Empty

Except there is no option to do any of those obvious things:

enter image description here

Attempt#4

I also tried going into the Extended Events menu, and clicking Clear Data. But the option is inexplicably disabled:

enter image description here

Attempt#5

I also tried to script the Extended Events Session, in order to see where it is storing the files. But of course SQL Server team is not helpful:

ADD TARGET package0.event_file(SET filename=N'Expensive Queries',max_file_size=(25),max_rollover_files=(4)),

Attempt#6

In SQL Server Profiler. If you wanted to clear the events you pushed the button to clear the events:

enter image description here

SQL Profiler is deprecated, and it's replacement provides no way to clear the events.


What is the way to clear the events?

Bonus Reading

  • Query to clear sql server logs over a certain age
  • Clear events in file target?
  • BOL: Targets for Extended Events in SQL Server
  • BOL: Event File Target
like image 217
Ian Boyd Avatar asked Feb 16 '18 15:02

Ian Boyd


People also ask

How do I delete XEL files?

To delete an Excel file through Windows Explorer, go to the folder where your file is saved, and right-click on the file, and choose Delete. As a result, the file is moved to the Recycle Bin. You can do the same thing by selecting the file, and pressing the Delete button on your keyboard.

How do I read an extended event .XEL file?

The regular menu of File > Open > File. Right-clicks in the Object Explorer under Management > Extended Events. The special menu Extended Events, and the special toolbar for Extended Events.

How do I open an Xel file in SQL Server?

You need a suitable software like SQL Server Mangement Studio to open a XEL file. Without proper software you will receive a Windows message "How do you want to open this file?" or "Windows cannot open this file" or a similar Mac/iPhone/Android alert.

What are extended events SQL?

What is SQL Server extended events? SQL Server Extended Events is a performance monitoring tool that helps to collect and monitor the database engine actions to diagnose problems in SQL Server. Microsoft has introduced the extended events with the SQL Server 2008 and then decided to retire the SQL profiler.


1 Answers

By default the path seems like it would be

C:\Program Files\Microsoft SQL Server\MSSQLXX.MSSQLSERVER\MSSQL\Log\*.xel

or basically wherever the system files are kept for SQL Server (i.e. the default ERRORLOG location). If there is nothing there then it may be that your Extended Event is set to ring buffer in which case only the latest information is kept and it's stored in memory. Seems the only way to clear the log in this case would be to stop and start the session.

like image 96
Element Zero Avatar answered Nov 18 '22 10:11

Element Zero