# How to find slow query in which project / page /user client

**URL:** <https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 17, 2024, 1:16am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916 "2024-06-17T01:16:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 17, 2024, 1:16am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/1 "2024-06-17T01:16:04Z")

</div>

There is a slow query in my project that is taking more than 12 minutes to run. From the active query page in the database, I can see the following query:

SELECT a."tagpath", b."drvid" FROM sqlth\_te a left join sqlth\_scinfo b on b."id"=a."scid" WHERE a."retired" is null OR a."retired"=0

I have searched my project using keywords like "sqlth\_scinfo", "sqlth\_te", and "retired", but I did not find any query or script with these names embedded in my views. I assume that these scripts are system generated.

Could anyone suggest how I should debug this slow query issue and identify which session, project, or user triggered it?  
If anyone can suggest how to improve it, that's even better.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/1/210733f2af9305a7872fd759dd519f4ded931faa.png)

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [June 17, 2024, 2:55am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/2 "2024-06-17T02:55:22Z")

</div>

This is tag history. You are most likely requesting a lot of data in a table, trend, chart, etc.

---

<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:** [June 17, 2024, 3:12am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/3 "2024-06-17T03:12:58Z")

</div>

See [Ignition Database Table Reference | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/ignition-database-table-reference#tag-history---internal-history-provider) for some information on the table descriptions.

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 17, 2024, 4:30am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/4 "2024-06-17T04:30:30Z")

</div>

Thanks for your reply.  
But how can I find out which session/page requesting lots of data.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 17, 2024, 5:54am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/5 "2024-06-17T05:54:08Z")

</div>

How many do you have with these types of components? Perhaps if nothing is showing up in the search, you could take a systematic approach and temporarily remove them one at a time until you find the one that is causing the problem. If nothing else, those components will be definitively ruled out as the problem.

---

<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:** [June 17, 2024, 8:27am UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/6 "2024-06-17T08:27:19Z")

</div>

Tidied-up query:

```python
SELECT 
    a."tagpath", 
    b."drvid" 
FROM sqlth_te a 
LEFT JOIN sqlth_scinfo b 
  ON b."id" = a."scid" 
WHERE a."retired" IS NULL OR a."retired" = 0

```

From the [Ignition Database Table Reference | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/ignition-database-table-reference#sqlth_te:)

> **sqlth\_te.tagpath** : Path of the Tag in the Tag Provider, i.e., Folder1/tag1.

> **sclth\_scinfo.scname** : Name of the tag group. A value of "_exempt_" is used in cases where the execution rate is not recorded, such as tags set to an "On Change" sample mode.

This shouldn't take long unless you have millions of tags or a table index is missing or corrupt.

As a first step in debugging, paste the query into whatever tool you use to manage your database and see what the execution time is.

The next thing I'd do is check that the indexes exist using the same tool.

`sqlth_te` should have two indexes:

- `PRIMARY` on the `id` column.
- `sqlth_tetagpathndx` on the `tagpath` column.

`sclth_scinfo` should have one index:

- `PRIMARY` on the `id` column.

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 17, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/7 "2024-06-17T13:48:40Z")

</div>

It's production enviroment, I can't risk to do this.

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 17, 2024, 2:28pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/8 "2024-06-17T14:28:29Z")

</div>

The index is present and the table is not corrupt. However, when the slow query occurs, running the script in MSSQL studio also gets stuck and does not produce any result. During non-busy hours, it takes less than a second to retrieve the result, which consists of 4500 records.

---

<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:** [June 17, 2024, 2:31pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/9 "2024-06-17T14:31:38Z")

</div>

> [@Lina\_Su](#):
>
> During non-busy hours, it takes less than a second to retrieve the result, which consists of 4500 records.

Sounds like your database server needs more resources.

---

<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:** [June 17, 2024, 2:32pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/10 "2024-06-17T14:32:41Z")

</div>

OK.  
You'll need to outline your configuration.

- Ignition gateway is running on Windows? Which version of Ignition and which of Windows?
- MS SQL Server is running on Windows?
- Is SQL Server on a different machine or the same one as the gateway?
- Are there any virtual machines involved?
- What does Task Manager show on the database machine?

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 18, 2024, 12:07pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/11 "2024-06-18T12:07:41Z")

</div>

1. Ignition gateway is running on Windows server 2019.
2. MS SQL Server is running on Windows server 2019.
3. SQL Server on a different machine as the gateway
4. Are there any virtual machines involved , yes, both virtual machine.
5. What does Task Manager show on the database machine - did not capature this informatiion, need server administrator to assist.

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 18, 2024, 12:12pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/12 "2024-06-18T12:12:40Z")

</div>

Is there a report from Ignition support me to apply more resource to my database administrator , similar to CPU/ memory usage report.  
Can the report verify that the issue is not due to the application's architecture, but rather a bottleneck within the database itself?

---

<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:** [June 18, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/how-to-find-slow-query-in-which-project-page-user-client/91916/13 "2024-06-18T12:22:59Z")

</div>

No, database load issues are database brand specific, and are outside Ignition's scope. You need your database admin to help you further.
