# Database Trigger Module

**URL:** <https://forum.inductiveautomation.com/t/database-trigger-module/84270>\
**Category:** Module Development\
**Tags:** perspective\
**Created:** [January 15, 2024, 2:39pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270 "2024-01-15T14:39:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subin\_Adhikari](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Subin\_Adhikari](https://forum.inductiveautomation.com/u/Subin_Adhikari)\
**Post date:** [January 15, 2024, 2:39pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270/1 "2024-01-15T14:39:58Z")

</div>

Hello Gurus,

I was wondering if there could be some database trigger setup. What I am looking for is

1. whenever named queries are processed I want to log the ms it took to execute them.
2. whenever runPrepQuery / runQuery are executed from the code, I want to log the ms it took to execute them.

can someone please guide me on the right steps?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 15, 2024, 2:46pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270/2 "2024-01-15T14:46:01Z")

</div>

If they're run from a script then it should be just a matter of recording [`system.date.now`](https://docs.inductiveautomation.com/display/DOC81/system.date.now?src=sidebar) to a variable before the query execution and then [`system.date.millisBetween`](https://docs.inductiveautomation.com/display/DOC81/system.date.*Between) after the end of the execution. You can then write the result out to a logger of some sort or on a status line in your application.

I can't think of a way you could do that with a query binding though.

---

<div class="post-metadata">

**Author:** ![Subin\_Adhikari](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Subin\_Adhikari](https://forum.inductiveautomation.com/u/Subin_Adhikari)\
**Post date:** [January 15, 2024, 2:46pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270/3 "2024-01-15T14:46:58Z")

</div>

I was looking to make/build a module for the same, any right direction is much appreciated 🙂

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 15, 2024, 2:51pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270/4 "2024-01-15T14:51:05Z")

</div>

I can't help you with that, but it occurred to me that you might be able to have the database log the queries and their execution time.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 15, 2024, 4:40pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270/5 "2024-01-15T16:40:52Z")

</div>

I don't think even an SDK module would be able to do this. The only possibility that comes to mind would be to implement a JDBC driver "wrapper" that would log what you like while passing the work onto a real JDBC driver.

---

<div class="post-metadata">

**Author:** ![Subin\_Adhikari](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Subin\_Adhikari](https://forum.inductiveautomation.com/u/Subin_Adhikari)\
**Post date:** [January 15, 2024, 9:01pm UTC](https://forum.inductiveautomation.com/t/database-trigger-module/84270/6 "2024-01-15T21:01:42Z")

</div>

> [@Longest Recent Queries Trace](https://forum.inductiveautomation.com/t/longest-recent-queries-trace/37560/4):
>
> Correct. Just the logs. The long running query tracker has a hardcoded limit of 10 per datasource.

I wish this was not hardcoded for 10 per data source so that we can enable/disable it upon requirement.

I believe what I want to achieve is already built-in ignition with few limitations. Thank you so much, Ignition Team.
