# Setting statement\_timeout

**URL:** <https://community.cratedb.com/t/setting-statement-timeout/1814>\
**Category:** CrateDB\
**Created:** [July 23, 2024, 10:39am UTC](https://community.cratedb.com/t/setting-statement-timeout/1814 "2024-07-23T10:39:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![djbestenergy](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@djbestenergy](https://community.cratedb.com/u/djbestenergy)\
**Post date:** [July 23, 2024, 10:39am UTC](https://community.cratedb.com/t/setting-statement-timeout/1814/1 "2024-07-23T10:39:25Z")

</div>

Hi all,  
I read in a document that running  
SET GLOBAL PERSISTENT statement\_timeout = ‘2m’;

Would set the timeout to 2 minutes for the whole cluster ?  
Is this the correct way , as I’m getting statements running longer than this ?.

Oh and we’re using CrateDB in the cloud, so we don’t have access to command line settings,etc

Many thanks  
David

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [July 23, 2024, 10:55am UTC](https://community.cratedb.com/t/setting-statement-timeout/1814/2 "2024-07-23T10:55:01Z")

</div>

The command `SET GLOBAL PERSISTENT statement_timeout = '2m';` sets the statement timeout for **all new sessions** to 2 minutes.

> Is this the correct way, as I’m getting statements running longer than this?

In theory, this is still possible because some statements are not interrupted, such as the execution of a slow scalar or the creation of a snapshot. If you have an example we might be able to identify the reason.

> Oh, and we’re using CrateDB in the cloud, so we don’t have access to command line settings, etc.

We can always set this up for you. Additionally, you can change the default with `SET GLOBAL` as you mentioned, or provide a session setting during connection or within a session with `SET statement_timeout = '2m';`.

---

<div class="post-metadata">

**Author:** ![djbestenergy](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@djbestenergy](https://community.cratedb.com/u/djbestenergy)\
**Post date:** [July 23, 2024, 10:59am UTC](https://community.cratedb.com/t/setting-statement-timeout/1814/3 "2024-07-23T10:59:21Z")

</div>

OK great , thanks for the information.

As we’re using cURL types calls, does this mean on a per session basis, we prepend the string  
`SET GLOBAL PERSISTENT statement_timeout = '2m';`  
before the select statements ?  
e.g.  
SET GLOBAL PERSISTENT statement\_timeout = ‘2m’; SELECT uuid,ts … "  
(We’re only need this for queries)

Many thanks  
David

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [July 23, 2024, 3:11pm UTC](https://community.cratedb.com/t/setting-statement-timeout/1814/4 "2024-07-23T15:11:03Z")

</div>

> As we’re using cURL types calls, does this mean on a per session basis, we prepend the string  
> `SET GLOBAL PERSISTENT statement_timeout = '2m';`  
> before the select statements ?

To adjust the statement\_timeout just for a single session, you would use `SET statement_timeout = '2m'` without the `GLOBAL PERSISTENT`.

However currently, sessions in CrateDB using the HTTP endpoint are tied to the TCP session, and the HTTP endpoint only supports single-statement SQL queries. This means that to run multiple queries one needs to issue multiple POST requests within the same TCP session or you need to use a pgwire protocol client/driver. However, with the release of CrateDB 5.9, we will introduce the ability to set session defaults at the user level.

---

<div class="post-metadata">

**Author:** ![matriv](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/matriv/32/613_2.png) [@matriv](https://community.cratedb.com/u/matriv)\
**Post date:** [July 23, 2024, 4:28pm UTC](https://community.cratedb.com/t/setting-statement-timeout/1814/5 "2024-07-23T16:28:13Z")

</div>

The aforementioned PR about session settings at user level: [Implement USER session settings by matriv · Pull Request #16345 · crate/crate · GitHub](https://github.com/crate/crate/pull/16345)
