# How best to run a DB query on a timed basis?

**URL:** <https://forum.inductiveautomation.com/t/how-best-to-run-a-db-query-on-a-timed-basis/42834>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 1, 2021, 7:08pm UTC](https://forum.inductiveautomation.com/t/how-best-to-run-a-db-query-on-a-timed-basis/42834 "2021-02-01T19:08:44Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 1, 2021, 8:50pm UTC](https://forum.inductiveautomation.com/t/how-best-to-run-a-db-query-on-a-timed-basis/42834/4 "2021-02-01T20:50:04Z")

</div>

> [@peter](#):
>
> Can you elaborate on this? Who is subscribing to whom?

When you create a Gateway Tag Change Script you add the tags that the event should be subscribed to. See [Tag Change Scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts#GatewayEventScripts-TagChangeScripts) for a better explanation. Basically, any tag that the event is subscribed to will cause the script to run.

The triggering tag value and path are available from the script so it is a fairly simple task to write a generic script that will execute your query using the specific triggering tags information.

> [@peter](#):
>
> I currently have 2 value change event scripts per UDT, with the potential 100+ instances. However, the rate of execution of those scripts is only about once every minute. This is the only data in the entire system (no visualization at all) so I hope that I won’t overtax that thread pool (can you change that default?)

It's hard to say and a lot of it has to do with how intensive the scripts are. I learned this lesson the hard way and spent about a month or so converting numerous valueChange scripts over to Gateway Tag Change Scripts.

Don't misunderstand, valueChange scripts have their uses, but most of the time Tag Change Scripts are superior.

This will provide some understanding on the topic.

> [@Tag Change Missed Events](http://forum.inductiveautomation.com/t/tag-change-missed-events/37764/13):
>
> Another tag script performance piece that may be affecting OP is that there is a dedicated thread pool size 3 that all tag change scripts are executed on. So in addition to having a per-tag queue of size 5 that events will sit in, there’s only ever 3 tag change scripts executing at once. This is where you can really get into trouble with long running scripts (as @pturmel hinted), because if you have 3 long running scripts then nothing else is executing until at least one of them finishes.

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-best-to-run-a-db-query-on-a-timed-basis/42834)._
