Trim audit log to Improve Performance in SharePoint

Requirement: Trim Audit log in SharePoint On-Premises.

Found SharePoint content databases were growing even when no content was added from the user side. I was analyzing SharePoint Database growth, went ahead and generated a disk space report from SQL Server Management Studio (Right-click the database, choose Reports >> Standard Reports >> Disk Usage by Table), which gave me a clear picture: AuditData table was growing rapidly and occupying more disk space.

trim audit log sharepoint

This is because the auditing feature is turned ON for several months, and Audit logs are stored in the AuditData table of the content database. The auditing feature is great, but it can take so much disk space eventually, and we definitely want to put some cap to preserve system resources, especially database disk space.

SharePoint 2010 provides the interface to specify the number of days to retain audit logs, and also provides an option to export the audit logs before truncating.

sharepoint 2010 trim audit log

So, we can adjust the settings to export and clear the audit logs in an interval.

Delete All Audit Logs

So, You noticed the logs are filling the disk space and want to delete all the audit logs, right? No issues. Let’s call PowerShell to the rescue. Let’s delete all audit entries that happened before 30 days.

$site = Get-SPSite -Identity http://sharepoint.company.com

#Get the date - last 30 days ago
$date = Get-Date
$date = $date.AddDays(-30)

#Delete Audit logs
$site.Audit.DeleteEntries($date)

More info: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spaudit.deleteentries

How to trim the audit log in SharePoint 2007?
In MOSS 2007 (after sp2), We have to manually do this trimming with STSADM -o trimaudtilog.
After executing the above stsadm command, shrink the database manually to regain the disk space.

stsadm -o trimauditlog –enddate 20120101 –databasename WSS_Content_Func_Finance

These trimming operations could cause blocks in the database, which can prevent SharePoint sites from loading. STSADM -o TrimAuditLog Reference:
http://technet.microsoft.com/en-us/library/cc706879%28v=office.12%29

The above method of trimming the audit log doesn’t provide any way to export the audit log. So, here is the workaround, object model code which exports the audit logs programmatically and deletes them!

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “Trim audit log to Improve Performance in SharePoint

  • This article no longer exists…

    Reply
  • So its not a document management system if you trim information on who did what when.. might as well use a file share it would be cheaper..

    Reply
  • This is a brilliant article, helped us a lot in reducing the size of our database and increasing the site performance.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *