# Find history partition size dynamically?

**URL:** <https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 29, 2023, 4:56pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526 "2023-08-29T16:56:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 29, 2023, 4:56pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/1 "2023-08-29T16:56:18Z")

</div>

I'm trying to write a bit of code that can be run on a few different gateways without issue, but it needs to know the history partition size of the gateway to be useful and these gateways are all configured differently. I could hard-code a table of partition sizes per gateway name and look them up, but I'm hoping there might be a way to dynamically find a history providers partition size from a script so I don't inevitably break something when someone changes the partition size a year or more from now and forgets about this script.

I dug through all the System tags and didn't find anything like I wanted.

Are there any hidden API calls that could make this happen?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 29, 2023, 6:59pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/2 "2023-08-29T18:59:49Z")

</div>

How dirty are you willing to get ?

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 29, 2023, 7:03pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/3 "2023-08-29T19:03:46Z")

</div>

All of our servers are either monthly or weekly so far ... I did the lazy detection based on how the current partition name was formatted, either `sqlt_data_1_yyyyMMdd` or `sqlt-data_1_yyyy_MM`. This will explode if we ever go to a partition size other than weekly or monthly, but I have more confidence in that particular risk.

Did you have a better idea? I was contemplating just looking at the `(end_time - start_time)` size of the current partition and guessing from that...

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 29, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/4 "2023-08-29T19:09:43Z")

</div>

I had nothing, but I'm home alone on kid watch duty. I have beer and nothing to do.

---

<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:** [August 29, 2023, 7:11pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/5 "2023-08-29T19:11:52Z")

</div>

> [@justin.brzozoski](#):
>
> I was contemplating just looking at the `(end_time - start_time)` size of the current partition and guessing from that...

I'd do this. From a voice of experience having looked at this area of the code...  
You're in for a world of hurt trying to retrieve it from scripting.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 29, 2023, 7:15pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/6 "2023-08-29T19:15:25Z")

</div>

Well... Not that this isn't an annoying bit of pain, also. Peeking at our current partition table I was just reminded that there is some sort of partition fragmentation bug afflicting us. The same name is repeated over and over with adjacent non-overlapping times... So, I'm really looking for this:

```auto
SELECT MAX(end_time)-MIN(start_time) FROM sqlth_partitions 
WHERE pname = (SELECT pname FROM sqlth_partitions WHERE ? BETWEEN start_time AND end_time LIMIT 1)

```

But ... yeah ...

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 29, 2023, 7:26pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/7 "2023-08-29T19:26:01Z")

</div>

No sane way to query the sqlite config DB? It's right there in `TAGHISTORIANPROVIDERSETTINGS`

Just scan the `./data/db/autobackup` directory to find the most recent inactive one, open it up and run a few selects... 🙂 (this would not work both for risk/sanity issues, but also since our sqlite DB is getting biggish at 400+MB and would be a heavy thing to open)

---

<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:** [August 29, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/find-history-partition-size-dynamically/78526/8 "2023-08-29T19:39:08Z")

</div>

> [@justin.brzozoski](#):
>
> sane

Nope.

Perhaps we should go for the step back of the XY problem here 🙂
