# Database timeouts #8663

**URL:** <https://forum.inductiveautomation.com/t/database-timeouts-8663/43483>\
**Category:** Ignition\
**Tags:** database\
**Created:** [February 16, 2021, 8:46pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483 "2021-02-16T20:46:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 16, 2021, 8:46pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/1 "2021-02-16T20:46:27Z")

</div>

[logs.zip](https://forum.inductiveautomation.com/uploads/short-url/trLVNBYJFNB1hMtUkPgWy45wg4p.zip) (2.0 MB)

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 16, 2021, 8:47pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/2 "2021-02-16T20:47:28Z")

</div>

```auto
Traceback (most recent call last):
  File "<event:propertyChange>", line 7, in <module>
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Read timed out

	caused by GatewayException: Read timed out
	caused by SocketTimeoutException: Read timed out

Ignition v8.1.1 (b2020120808)
Java: Azul Systems, Inc. 11.0.7

```

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 16, 2021, 8:57pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/3 "2021-02-16T20:57:40Z")

</div>

![Database Disk usage by table report](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/5301b695327e6149a20b90de293cd4e85daa86cd.jpeg)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 16, 2021, 8:59pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/4 "2021-02-16T20:59:38Z")

</div>

Seems like your query is taking longer than your designated timeout. If your timeout is 60 seconds and the query takes 70 seconds you won’t see the data and get the error instead.

You can modify the timeout period on the project properties -

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

Alternatively, probably what I would do first, you can try optimizing your query. Get the EXPLAIN statement for your query and see if there’s any indexes or optimizations you can do.

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 16, 2021, 9:04pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/5 "2021-02-16T21:04:11Z")

</div>

Hi, Thanks for the input! I’m sorry there isn’t more information immediately, this is the only way I could data out to the support team.

I’ve built an application which uses an easy chart and tag historian see [Start and End data values](http://forum.inductiveautomation.com/t/start-and-end-data-values/42912) for more information on it.

On Thursday last week I was testing the application and response times were very acceptable, perhaps a few seconds to update the easy chart when dates were changed. Friday I went to setup this on the managers desktops and the application comes up with these really long SELECT queries leading to timeouts in the order of 20+ minutes.

I’m checking back to see if anything changed with the scripting or database, I might need to get the IT guys involved as they made changes to firewall rules to allow managers access to the production network.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 17, 2021, 1:32pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/6 "2021-02-17T13:32:23Z")

</div>

Ok. Overall though, `caused by GatewayException: Read timed out` errors with regards to database queries just means that the query you want to run takes longer than the preset timeout setting you set. So the only two ways to attack this are to make the query complete faster via optimization or whatever idea’s your IT team has, or to increase the timeout. However, given you said the queries are taking 20 minutes now which I am going to guess is unacceptable, you probably want to optimize/fix whatever technical bottleneck is causing the slowness.

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 17, 2021, 11:32pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/7 "2021-02-17T23:32:10Z")

</div>

Support tried a few queries directly on the database, and it seems to be the problem, doesn’t respond very quickly. I don’t know very much about databases (using SQL Express here) so I don’t know what to look at for fixes. So far I changed this in ignition.conf:

```auto
# Initial Java Heap Size (in MB)
#20210217 changed from 1024 to 1100
wrapper.java.initmemory=1100

# Maximum Java Heap Size (in MB)
#20210217 changed from 2048 to 4400
wrapper.java.maxmemory=4400

```

with no noticeable changes to easy chart updates.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 18, 2021, 1:20pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/8 "2021-02-18T13:20:19Z")

</div>

Ok the heap size is something different from the timeout. If you were running a gateway script that had something like

```auto
results = system.db.runQuery("SELECT * FROM myTable")

```

and you had millions of millions of row, then you could have a Heap Size problem and could face an issue.

But query timeout is send out a query to the database and it takes the database longer than your timeout to get any result.

So again that is under project properties per the last post.

I see you are referencing an easy chart update. Is this for a historical tag or something? You might want to look into setting up pruning as otherwise the table just gets larger and larger and the query will take longer and longer (unless you set up the component to initialize with some recent date parameters, which may be something else to try).

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 18, 2021, 11:15pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/9 "2021-02-18T23:15:49Z")

</div>

> [@bkarabinchak.psi](#):
>
> I see you are referencing an easy chart update. Is this for a historical tag or something? You might want to look into setting up pruning as otherwise the table just gets larger and larger and the query will take longer and longer (unless you set up the component to initialize with some recent date parameters, which may be something else to try).

Yes, this is an easy chart using tag historian. Sometimes the data on the chart will span a few days, tags are updated every 2 seconds, current data tables are as I posted above, several million records. Part of the project requirements is the retention of this data for up to 30 years. I don't think it's required to be immediately accessible, but the data cannot be deleted or discarded. Maybe I need to look into some sort of archiving behind the scenes, is this what you mean by pruning? When I was testing the application last week Thursday, it worked fine, then on Friday I started getting these timeouts. Shouldn't I have been seeing slower and slower responses as the tables grew in size, rather than this sudden timeouts?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 19, 2021, 11:50am UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/10 "2021-02-19T11:50:12Z")

</div>

No pruning would mean deleting data that is beyond X days/months/years old.

Yea I would expect slower responses as it grew in size. What’s your timeout set to?

Here’s what I would do - set your timeout super high - so that the query can finish. This way you can get the query in the Slow Query log, copy and paste it into your database workbench, and then run an EXPLAIN statement on the query so you can see if there’s a way to optimize it.

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 19, 2021, 5:00pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/11 "2021-02-19T17:00:25Z")

</div>

> [@bkarabinchak.psi](#):
>
> Yea I would expect slower responses as it grew in size. What’s your timeout set to?
> 
> Here’s what I would do - set your timeout super high - so that the query can finish. This way you can get the query in the Slow Query log, copy and paste it into your database workbench, and then run an EXPLAIN statement on the query so you can see if there’s a way to optimize it.

 ![Project Properties - Timing](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/d/bd06781865f78b2332748ab2ce1ef9938d3fe22f.jpeg)

This is the timing to change?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 19, 2021, 5:06pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/12 "2021-02-19T17:06:52Z")

</div>

Yes the Read Timeout. Right now if your query takes more than 1 minute you will get a Read Timeout error.

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 19, 2021, 5:36pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/13 "2021-02-19T17:36:52Z")

</div>

I changed the timing from 60000 to 60 000 000 and from 120 000 to 120 000 000. Saved the project and relaunched it. Now my queries are running just fine. A little slow on some of them, but those are getting days worth of records.

 ![Database queries](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/2905f44f680c9e4eb2ac5c3556e024a2dd911436.jpeg)

I have no idea what changed (except for what I mentioned) to make it work suddenly.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 19, 2021, 5:40pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/14 "2021-02-19T17:40:11Z")

</div>

Ok thats good. I see some are taking many seconds, but they look like the queries Ignition knows to use. You can try what I said at this point - copy that top query that took 7 seconds, paste it into workbench, EXPLAIN the statement and see if you can optimize with indexes or similar.

However, since you said this will be 30 years of data, and already millions of rows, creating an index would take up a non-trivial amount of space. You could look into other techniques like data partitioning which is suitable for optimizing queries with date where clauses. I think that may be the way to go for you tbh - if you care to try to optimize the queries.

---

<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 19, 2021, 5:54pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/15 "2021-02-19T17:54:34Z")

</div>

I find it odd that a simple insert would take nearly 30s.

How do you have your data partitioning set up on the gateway?

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 19, 2021, 7:17pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/16 "2021-02-19T19:17:33Z")

</div>

I don’t know? I guess whatever the defaults are.

---

<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 19, 2021, 7:24pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/17 "2021-02-19T19:24:07Z")

</div>

I believe the default is 1 Month.

How many items are you collecting and how often (e.g. how fast is your table growing)? You may want to consider setting you partitioning to a shorter rate.

This is configured in the Historical Provider.

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 19, 2021, 7:25pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/18 "2021-02-19T19:25:46Z")

</div>

Using historical tags, 8 of them, and updating at 2 second intervals. I will look into Historical Provider.

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.inductiveautomation.com/u/robb)\
**Post date:** [February 19, 2021, 7:45pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/19 "2021-02-19T19:45:18Z")

</div>

This is where the Historical Provider is configured? I don’t see where partitions is setup, but I do see an option for partitions when I’m on SQL Server Manager, if I right click the tables.

 ![Tag History configuration](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/292b72689f17794902f4979bbcb303f47c602cfe.jpeg)

Ignore that, found it in Config \> Tags \> History on the gateway. I believe it’s all on defaults. Should I try setting it to weekly? What happens if data is requested from an old partition?

 ![Partitions](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b90f55f5b52c451c8dcad5161eda35514540b2f6.jpeg)

---

<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 19, 2021, 8:08pm UTC](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483/20 "2021-02-19T20:08:09Z")

</div>

I mean, you’re collecting 1.4M rows per day, that is a significant amount of data.

The query will need to join the two tables together to return the result. The built in historical functions take care of joining the tables together for you.

[Next page](https://forum.inductiveautomation.com/t/database-timeouts-8663/43483.md?page=2)
