Skip to content

[BUG] Trace files never get cleaned up #951

@mike-hodgson-icon

Description

@mike-hodgson-icon

Component

Full Dashboard

Performance Monitor Version

2.10

SQL Server Version

SQL Server 2019 CU32

Windows Version

Windows Server 2022 Standard Edition

Describe the Bug

Trace files (N'Monitor_LongQueries_*.trc') get created in the MSSQL errorlog directory by [collect].[trace_management_collector] and are dissected by [collect].[trace_analysis_collector] to grab info for long running queries, but they are never cleaned up (i.e. deleted) by [config].[data_retention]. The default retention for the trace files is 30 days.

Image

Steps to Reproduce

  • Open dashboard
  • Add server
  • Let that run for > retention days for its Trace Management collector schedule
  • Check MSSQL errorlog directory for "Monitor_LongQueries_*.trc"

Expected Behavior

"Monitor_LongQueries_*.trc" should get deleted by [config].[data_retention] when they're older than retention_days from config.collection_schedule where collector_name = N'trace_management_collector'. My suggestion would be to use xp_delete_file, even though it's undocumented, to delete files older than the retention date with something like:

exec master.dbo.xp_delete_file
	1,                                /* 1 = delete files older than cutoff date  */
	N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Log\Monitor_LongQueries_*.trc',
	N'trc',
	'2026-04-12T08:00:00.000';             /* delete .trc files older than this date   */

...assuming you derive the path (there's code at the start of [collect].[trace_management_collector] to do that - easy copy/paste) and the appropriate retention date.

Actual Behavior

Trace files accumulate indefinitely, as far as I can see, and will eventually fill the disk where the errorlog files sit. One of my servers currently has 106 Monitor_LongQueries_*.trc files accounting for almost 7GB of disk, going back almost 2 months. When the server is particularly busy a single trace can rollover to many trace files, with a max rollover file size of 200MB theoretically (although my earlier trace files were mostly rolling over at about 110-180MB).

Image

Error Messages / Log Output


Screenshots

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions