# Deleting historical records from the module code

**URL:** <https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048>\
**Category:** Module Development\
**Created:** [June 18, 2024, 8:06pm UTC](https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048 "2024-06-18T20:06:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Christopher\_Campbell](https://forum.inductiveautomation.com/u/Christopher_Campbell)\
**Post date:** [June 18, 2024, 8:06pm UTC](https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048/1 "2024-06-18T20:06:42Z")

</div>

I have a module that is using the DatasourceManager to create a table in a SQL db and write BasicHistoricalRecords. I would like to be able to prune data from this table that is too old, or based on another event. I cannot find anything in the SDK to support this effort to delete records from that table. Is that not possible? The only option I have at this time would be to use a SQL job to delete records but I would love to leave this functionality inside of the module code.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 18, 2024, 8:37pm UTC](https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048/2 "2024-06-18T20:37:15Z")

</div>

Wait, as in, you've got a module (that's not a historian implementation) that's creating `BasicHistoricalRecord`s and, what, calling `storeToConnection` directly? That's...unorthodox. `BasicHistoricalRecord` has a lot of assumptions baked into it related to the tag historian, and really isn't meant to be a general purpose class.

---

<div class="post-metadata">

**Author:** ![Christopher\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Christopher\_Campbell](https://forum.inductiveautomation.com/u/Christopher_Campbell)\
**Post date:** [June 18, 2024, 8:57pm UTC](https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048/3 "2024-06-18T20:57:30Z")

</div>

I am using storeHistory() to write the BasicHistoricalRecord. So far it is working great but it would be nice to manage the table size from within the module to allow for the removal of data that is too old.

The customer has Remote Tag Providers that are already storing values in a database but they don't want any additional load put on those databases for data retrieval. I don't see how you could mark a tag to be using more than one historian so this approach has allowed for storage of a subset of tags on the RTP in a separate database. I don't see how to take advantage of the partitioning and pruning functionality on this secondary database though.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 18, 2024, 9:07pm UTC](https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048/4 "2024-06-18T21:07:10Z")

</div>

This seems like the entire operation could just be managed via the tag history splitter, and then you don't even need a custom module - just configure native pruning on each 'sub' connection of the splitter.

> **[Tag History Providers | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/tag-historian/tag-history-providers#tag-history-splitter)**
>
> The Tag Historian module uses a concept of "History Providers" as a means to keep track of different storage configurations. Each provider is responsible for maintaining its own set of tables and records.

---

<div class="post-metadata">

**Author:** ![Christopher\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Christopher\_Campbell](https://forum.inductiveautomation.com/u/Christopher_Campbell)\
**Post date:** [June 18, 2024, 9:26pm UTC](https://forum.inductiveautomation.com/t/deleting-historical-records-from-the-module-code/92048/5 "2024-06-18T21:26:53Z")

</div>

Thanks for the response. I will look into the Splitter concept. The Remote TP has 80k tags but we only want to collect 5000 of them into a separate DB to prevent any additional load on their primary DB.
