How to modify retention duration for Workflow Instances completed in Workflow Manager

Workflow Manager implements several System workflows to make sure that WFM databases are working healthy.

By default, 'Completed' and 'Terminated' workflow instances are purged from “WFInstanceManagementDB”  database after 30:00:00:00 days (DD:HH:MM:SS ). If you need to modify that default behavior, you should execute below steps:

a)      Open a WFM PowerShell command.

b)      Execute below powershell cmdlet. Please keep in mind that increasing excessively the retention windows time for completed workflow Instances might cause a performance degradation on Workflow Databases.

Set-WFServiceConfiguration -ServiceUri <Workflow Management WebSite URI> -name WorkflowServiceInstanceRecordRetentionDuration -value <DD:HH:MM:SS>

Note: That change will apply to all new Workflow instances executed from that moment on. All existing workflow will be purged at the time specified on “Expiration” column ([WFInstanceManagementDB].[dbo].[Instances])

c)      To verify that the value has been changed properly, execute next command:

Get-WFServiceConfiguration -ServiceUri <Workflow Management WebSite URI> -name WorkflowServiceInstanceRecordRetentionDuration

 d)      Restart WFM services so that the change takes effect: Open a Workflow Manager Powershell command and execute "Stop-WFHost" and then "Start-WFHost" in every WFM server.


If you have a SharePoint 2013 connected with Workflow Manager, you should define the same retention period cleanup in both Workflow Manager (WorkflowServiceInstanceRecordRetentionDuration setting) and SharePoint (Timer job "Workflow Auto Cleanup"). Otherwise, SharePoint will not be completely aligned with the information stored at Workflow Manager Database, and you might get below error in SharePoint when trying to see Workflow execution history:

w3wp.exe   (0x8A70)        0xB348 SharePoint   Foundation             Runtime            Unexpected       Microsoft.SharePoint.SPException: We can't find that workflow.    at Microsoft.SharePoint.WorkflowServices.ApplicationPages.WrkStatPage.OnLoad(EventArgse)     at
System.Web.UI.Control.LoadRecursive()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 

Hope it helps!!