How to delete Assets Object History logs
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Atlassian Support Offerings
The following approaches that involves SQL queries are beyond Atlassian Support Offerings. Please note that Atlassian does not support direct database INSERT, UPDATE or DELETE queries, as they can easily lead to data integrity problems. Atlassian will not be held liable for any errors or other unexpected events resulting from the use of the following SQL queries.
Purpose
Removing an object's history logs through the Assets UI is currently not possible. This issue has been recorded as an area for improvement in Assets: JSDSERVER-8706 - Create a cleanup mechanism to Assets Object History
Until the product improvement is in place, this article aims to provide an alternative method for removing object's history records using database statements.
Environment
All versions of Assets management.
Solution
Before you begin
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
Table AO_8542F1_IFJ_OBJ_HIST stores the History values for existing Objects. To review all impacted entries and the database structure for potential adjustments, execute a select query on the object from which you intend to remove history:
SELECT * FROM "AO_8542F1_IFJ_OBJ_HIST"
WHERE "OBJECT_ID" = XXX;
To remove the history logs, you can either delete logs that are older than a specific date or specify an object ID for removal:
DELETE FROM "AO_8542F1_IFJ_OBJ_HIST"
WHERE "CREATED" < '2020-12-31 00:00:00.0';
OR
DELETE FROM "AO_8542F1_IFJ_OBJ_HIST"
WHERE "OBJECT_ID" = XXX;
The Object ID is the numeric part of the Object Key, and will also show in the Object URL when you navigate to the Object.
This is tested on PostgreSQL and may need modifying for other DBMS such as Oracle or SQL Server.
Deleting History entries will only remove the History records from the Object, no other part/functionality in Assets should be affected by removing the Object's History.
If you are using PostgreSQL, running the VACUUM FULL command is essential to prevent deleted data from occupying space in the table. This practice is highly recommended, especially when carrying out substantial updates, as detailed in Optimize and Improve PostgreSQL Performance with VACUUM, ANALYZE, and REINDEX.
Starting in JSM 5.7.0, the data in the AO_8542F1_IFJ_OBJ_HIST is referenced by Assets Imports to Manage Objects. Therefore, an import could fail to modify an existing object if there is no history of the import ever modifying the object. Please see: JSDSERVER-7225 - Insight Missing Objects across all import configurations along with Assets Objects are Not Marked as Missing by the Import and also Automatically Delete Objects that are Not Created by Asset Import Tasks for more information