Old files cleanup RRS feed

  • Question

  • Hi All,

    I want to create a job that automatically deletes trace(.trc) files older than 2 weeks.

    Tried creating one using sql maintenance plan.

    maintenance cleanup task-> gave the folder details, file extension as 'trc' & specified the retention period.

    The job is successful, but the files are not getting deleted.

    Tried with both options:

    delete files of type- backup, maintenance plan text report.

    Can you help?

    Monday, October 7, 2019 1:00 PM

All replies

  • If you're talking about the 5 files of the default trace, there will only ever be 5. When SQL creates a new one, it deletes the oldest, so there's no need for any manual cleanup task.


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence

    Monday, October 7, 2019 1:54 PM
  • Hi SSG92,

    >>The job is successful, but the files are not getting deleted.

    Could you please share us the log file generated by maintenance plan which are under LOG folder?

    Currently, could you please try execute the following command manually:

    EXECUTE MASTER.dbo.xp_delete_file 0,N'YourBackupLocation',N'trc',N'2019-10-08T17:00:00'


    This command can delete all trc files older than 2019-10-08T17:00:00.

    Please refer to this blog for more details.

    In addition, the Agent account needs to have read and write permissions to the folder.

    Hope this could help you.

    Best Regards,

    Amelia Gu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 8, 2019 9:19 AM