• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1080
  • Last Modified:

Auto-Deleting Audit Trace (.trc) Files

We have a Windows 2008 R2 server running MS SQL 2008. The .trc  files are putting a lot of stress on the disk space of our server and are being produced about every minute at 5 MBs a file. What are they for? Is there a way to limit the amount of files through SQL safely?
0
First Last
Asked:
First Last
  • 2
1 Solution
 
Deepak ChauhanSQL Server DBACommented:
Seems SQL profiler trace is creating the 5MB files using SQL server Profiler tool or usign SQL agent job.

Can you run this query on the sever

select * from sys.sysprocesses where program_name like '%profiler%' or lastwaittype = 'TRACEWRITE'

You can limit the trace file size by putting the value in "set maximum file size" value text box.
0
 
First LastAuthor Commented:
Can I set a retention policy also?
0
 
Deepak ChauhanSQL Server DBACommented:
Yes you can set retention policy but there is no any inbuild feature to auto remove the old files. You have to setup a SQL agent job which will perform this task for you.

You can delete the old files using  XP_cmdshell system stored procedures. Just schedule a sql job and copy the below code. Please change the parameters accordingly.

exec xp_cmdshell 'forfiles /P <D:\tracef\> /M *.trc /D -1 /C "cmd /c del @file" '

/P <File directory location>  , /D < number of old days > /M <search the extention> , /C < delete command>
0
 
Chandra Mohan KanithiPrincipal Consultant - DatabaseCommented:
Please find the Best solution for this issue is use the powershell script in T-SQL Job then schedule.

Get-ChildItem -Path "C:\SQLServer\Data" -include *.trc -recurse | Where {$_.LastWriteTime -lt  (Get-Date).AddDays(-14)} | Remove-Item -Force

Thanks,
Chandra
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now