How to clear SQL Server Extended Events Event File

╄→гoц情女王★ 提交于 2019-12-12 11:21:48

问题


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:

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:

Attempt#4

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

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:

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

回答1:


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.




回答2:


You can also use

DECLARE @SQLDataRoot VARCHAR(400)
EXEC master..xp_instance_regread @rootkey = 'HKEY_LOCAL_MACHINE', 
 @key = 'SOFTWARE\Microsoft\MSSQLServer\Setup', 
 @value_name = 'SQLDataRoot', @value = @SQLDataRoot OUTPUT
 SELECT @SQLDataRoot 


来源:https://stackoverflow.com/questions/48830499/how-to-clear-sql-server-extended-events-event-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!