The IN_DB_UTIL_SP_CLEANUP_WF_ARCH_DATA stored procedure can be used to cleanup archived workflow data. This procedure will delete data from the IN_WF_ITEM_ARCH and IN_WF_ITEM_HIST_ARCH and IN_WF_ITEM_QUEUE_HIST_ARCH tables based on the value of the KEEP_DAYS parameter or the BEGIN_DATETIME and END_DATETIME parameters.
WARNING The execution of this procedure to cleanup archived workflow data could result in lock escalation and create contention on the affected tables which could result in delays and errors during normal operations. It is advised to only execute this procedure after hours or on weekends while monitoring for database contention to ensure minimal impact to the Perceptive Content application. If necessary, utilize smaller batch sizes with the BATCH_SIZE parameter to help keep transaction sizes smaller and reduce the scope and duration of database locks.
When running this procedure you have the option to specify whether or not to delete archived workflow data for content that still exists (Folders and Documents). By default, this option (HAS_CONTENT) is set to 0 (NO) which restricts the procedure from deleting archived workflow data for folders and documents that still exist. To override this behavior, you can execute the procedure with HAS_CONTENT = 1 (YES) to indicate that you want to delete all qualifying archived workflow items regardless of whether there is referencing content that may still exist.
- If you use the HAS_CONTENT = 1 option to remove archived workflow content for documents and folders that still exist then be aware that it’s possible, depending on the specified time frame of the cleanup, that only part of the archived workflow history will be deleted for any given document or folder. This would result in an incomplete workflow archive history when viewing the properties for that document or folder. However, the remaining archived workflow history will be deleted the next time the procedure is executed if the specified time frame of the cleanup includes the remaining archived workflow history for the document or folder.
- You can use the MODE = 0 (COUNT) option to get a row count of qualifying rows based on the supplied values for the KEEP_DAYS or BEGIN_DATETIME and END_DATETIME parameters to determine the scope of the cleanup. Additionally, you can use the DISPLAY_ONLY = ‘YES’ option to display the generated SQL without executing it.
- If the parameter values provided during execution result in all archived workflow records qualifying for deletion then the three workflow archive tables will be truncated instead. This can also be accomplished by using KEEP_DAYS = 0 and HAS_CONTENT = 1 when executing the procedure.
Parameter | Description | |
---|---|---|
MODE | Type: | INPUT |
Datatype: | TINYINT | |
Default Value: | 0 | |
Description | Specifies whether to count or delete all qualifying rows. | |
Options |
0 = Count Rows 1 = Delete Rows |
|
HAS_CONTENT | Type: | INPUT |
Datatype: | TINYINT | |
Default Value: | 0 | |
Description | Specifies whether or not to remove archived workflow items from the workflow archive tables that still has existing content in the IN_DOC table (documents) and the IN_PROJ table (folders). | |
Options |
0 = Only delete archived workflow items for which the referencing content no longer exists. 1 = Delete all qualifying archived workflow items regardless of whether there is referencing content that may still exist. |
|
KEEP_DAYS | Type: | INPUT |
Datatype: | INTEGER | |
Default Value: | NULL | |
Description | Specifies the number of days of audit data that you want to keep. Uses DATEADD against GETUTCDATE(). | |
Options |
0 = Delete All Rows Any number of days greater than 0 |
|
BEGIN_DATETIME | Type: | INPUT |
Datatype: | NVARCHAR(40) | |
Default Value: | NULL | |
Description |
Specifies the start date[time] when deleting audit data based on a date range. Expected format is YEAR [MONTH] [DAY] [TIME] |
|
END_DATETIME | Type: | INPUT |
Datatype: | NVARCHAR(40) | |
Default Value: | NULL | |
Description | Specifies the end date[time] when deleting audit data based on a date
range. Expected format is YEAR [MONTH] [DAY] [TIME] |
|
CONVERT_TO_UTC | Type: | INPUT |
Datatype: | TINYINT | |
Default Value: | 1 | |
Description | Specifies whether to convert the entered BEGIN_DATETIME and END_DATETIME parameters to UTC. | |
Options |
0 = Do not convert to UTC 1 = Convert to UTC |
|
BATCH_SIZE | Type: | INPUT |
Datatype: | INTEGER | |
Default Value: | 100 | |
Description | Specifies the batch size if breaking up deletion into smaller transactions. Batch sizes greater than 1,000 could result in lock escalation and acquiring table locks on the audit tables which would block any inserts into the tables. | |
Options |
0 = Single transaction Any number greater than 50 |
|
USE_TIME | Type: | INPUT |
Datatype: | TINYINT | |
Default Value: | 0 | |
Description | Specifies whether to include the time parts for the date ranges. | |
Options |
0 = 12AM 1 = Current UTC time for KEEP_DAYS Time provided with the BEGIN_DATETIME and END_DATETIME parameters |
|
MAX_MINUTES | Type: | INPUT |
Datatype: | INTEGER | |
Default Value: | 0 | |
Description |
Specifies a time limit to determine whether to start deleting the next batch of rows. This only applies if using BATCH_SIZE greater than 0. Batches will run through completion but a new batch will not start if time has expired. |
|
Options |
0 = No Time Limit Any number of minutes greater than 0 |
|
DISPLAY_BATCHES | Type: | INPUT |
Datatype: | NVARCHAR(3) | |
Default Value: | YES | |
Description | Specifies whether to display the batch results and batch summary after each batch is completed. | |
Options | YES = Display the batch results after each batch. NO = Do not display the batch results after each batch. |
|
INCLUDE_SUMMARY | Type: | INPUT |
Datatype: | NVARCHAR(3) | |
Default Value: | YES | |
Description | Specifies whether to fetch and display the row counts of all qualifying rows for each table. Fetching summary data during execution could result in a much longer execution time as all qualifying rows are counted before any rows are deleted. | |
Options |
NO = Do not fetch and display the number of qualifying rows. YES = Fetch and display the number of qualifying rows for each table. |
|
DISPLAY_ONLY | Type: | INPUT |
Datatype: | NVARCHAR(3) | |
Default Value: | NO | |
Description | Specifies whether to only display the generated SQL statements. | |
Options |
NO = Execute the SQL. YES = Show the generated SQL without executing. |
|
DEBUG | Type: | INPUT |
Datatype: | NVARCHAR(3) | |
Default Value: | NO | |
Description |
Specifies whether to display the SQL being executed during the script. Will also display background operations including session setup and state changes and call stack details. |
|
Options |
NO = Do not display additional details to the Message tab. YES = Display additional details to the Messages tab. |
|
HELP | Type: | INPUT |
Datatype: | NVARCHAR(3) | |
Default Value: | NO | |
Description | Specifies whether to display the procedure usage examples. | |
Options |
NO = Do not display examples. YES = Only display examples. |
|
RETURN_VAL | Type: | RETURN |
Datatype: | INTEGER | |
Default Value: | 0 | |
Description |
Specifies whether the execution of the procedure was successful or not. 0 = Success 1 = Error |
Index Considerations
The following index change can be considered to facilitate improved index usage when using the default option of HAS_CONTENT = 0. Estimated improvement is 11.6%.
CREATE NONCLUSTERED INDEX [WF_ITEM_ARCH_IDX03] ON [inuser].[IN_WF_ITEM_ARCH]([ARCHIVE_TIME]) INCLUDE ([OBJ_ID]) WITH (DROP_EXISTING = ON, ONLINE = ON, DATA_COMPRESSION = PAGE) ON [SECONDARY];
Examples
Display Usage Information Only
EXEC [IN_CLEANUP_WF_ARCH_DATA] @HELP = 'YES' GO
KEEP_DAYS Example:
The following will delete all archived workflow data that is older than 365 days using batch sizes of 1,000 rows.
Note that from a transaction standpoint the number of rows is based on qualifying rows in the IN_WF_ITEM_ARCH table but the transaction also includes the deletion of rows from the IN_WF_ITEM_HIST_ARCH and IN_WF_ITEM_QUEUE_HIST_ARCH tables which will likely have more than 1,000 rows that correspond to the rows in the IN_WF_ITEM_ARCH table. That means that each transaction will affect significantly more rows than specified in the BATCH_SIZE parameter so beware of lock escalation that could result in table locks when using larger batch sizes.
Note that in the examples below the Results tab will only contain the results of the final select statement displaying the RETURN_VAL of the procedure (0 = Success and 1 = Error). The output of the procedure, including number of rows counted or deleted, is displayed in the Messages tab.
DECLARE @return_value integer EXEC @return_value = IN_CLEANUP_WF_ARCH_DATA @MODE = 1 ,@HAS_CONTENT = 1 ,@KEEP_DAYS = 365 ,@BEGIN_DATETIME = NULL ,@END_DATETIME = NULL ,@CONVERT_TO_UTC = 1 ,@BATCH_SIZE = 1000 ,@USE_TIME = 0 ,@MAX_MINUTES = 0 ,@DISPLAY_BATCHES = 'YES' ,@INCLUDE_SUMMARY = 'NO' ,@DISPLAY_ONLY = 'NO' ,@DEBUG = 'NO' SELECT 'Return Value' = @return_value GO
DATE RANGE Example:
The following example will delete archived workflow data that does not still reference existing content that was created on January 1, 2018 between 8am and 5pm using a batch size of 1,000 rows.
Note that to preserve the time part of the timestamps you must set USE_TIME = 1
Note that CONVERT_TO_UTC = 1 (default) which means the provided timestamps will be converted to the UTC timestamp so that it aligns with the timestamps in the database.
DECLARE @return_value integer EXEC @return_value = IN_CLEANUP_WF_ARCH_DATA @MODE = 1 ,@HAS_CONTENT = 0 ,@KEEP_DAYS = NULL ,@BEGIN_DATETIME = 'January 01 2018 8:00 AM' ,@END_DATETIME = 'January 01 2018 5:00 PM' ,@CONVERT_TO_UTC = 1 ,@BATCH_SIZE = 1000 ,@USE_TIME = 1 ,@MAX_MINUTES = 0 ,@DISPLAY_BATCHES = 'YES' ,@INCLUDE_SUMMARY = 'YES' ,@DISPLAY_ONLY = 'NO' ,@DEBUG = 'NO' SELECT 'Return Value' = @return_value GO