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?
First LastAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
First LastAuthor Commented:
Can I set a retention policy also?
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>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.