Customizing Operator Advisor > Logging Historical Data > Purging the Historical Data Database Table
Purging the Historical Data Database Table
The historical data database table can be purged manually or scheduled through the historical data purge scheduler (PTC.SCA.SCO.HistoricalDataPurgeScheduler). When the historical data database table is purged, only historical data is deleted, not the related data in any other database tables.
Purge Historical Data Service
The PurgeHistoricalData service is found on the historical data management Thing Shape (PTC.SCA.SCO.HistoricalDataManagementThingShape), and as a result can be executed from the default production order manager (PTC.SCA.SCO.DefaultProductionOrderManager). The input parameter for this service, DataAgeInDays, represents the age of the data to be retained in the historical data database table. For example, if the user specifies 14, any entries in the historical data database table that are older than 14 days are deleted. The PurgeHistoricalData service is called by the historical data purge scheduler at the frequency specified on the scheduler. While data can be purged manually using this service, using the scheduler is preferable.
Historical Data Purge Scheduler
The historical data purge scheduler (PTC.SCA.SCO.HistoricalDataPurgeScheduler) uses the ThingWorx Scheduler Thing Template. For Operator Advisor, the historical data purge scheduler calls the PurgeHistoricalData service on the default production order manager.
Three things must be configured for the historical data purge scheduler to be used: the DataAgeInDays property under Properties and Alerts, and the Schedule and Automatically Enable Timer on Startup fields under General Information.
Historical data purge scheduler, Properties and Alerts page.
The DataAgeInDays property on the historical data purge scheduler determines how long data in the database table remains in the database before it is purged. For example, a value of 28 means that any data older than four weeks (twenty-eight days) is purged from the database at the frequency specified for the Schedule property in the configuration table. By default, DataAgeInDays has a value of 14.
Historical data purge scheduler, Configuration page.
The Schedule field takes a cron job expression and handles the frequency at which the data is purged from the historical data database table. The default expression used for Operator Advisor (shown above) is the expression for purging data once a day, at midnight. For more information on formulating proper cron expressions, see the following ThingWorx support article: Thingworx: How To Format a Cron String. Many free websites can also generate cron expressions based on desired input.
The Automatically Enable Timer on Startup checkbox determines whether the scheduler is active. Unless the Automatically Enable Timer on Startup checkbox is selected, even if data in the historical data database table is eligible to be purged, the data is not purged. By default, the scheduler is not enabled.
* 
If you have ThingWorx Apps installed on the same ThingWorx system as Operator Advisor, the PTC.Factory.MidnightPurgeWeekOldHistoryScheduler is also present. This scheduler deletes historical sensor data which is older than one week from ThingWorx Apps. The historical data purge scheduler (PTC.SCA.SCO.HistoricalDataPurgeScheduler) and PTC.Factory.MidnightPurgeWeekOldHistoryScheduler delete separate information from the system, and do not conflict.
Was this helpful?