Set A Statement Timeout Threshold For A Session
Last updated
Was this helpful?
Last updated
Was this helpful?
The statement_timeout
variable is used to tell the PostgreSQL server that you want it to terminate statements (queries and transactions) that run past the specified threshold. This is a great way to in a production environment.
You can set this threshold with a set
statement. It can take an integer argument of milliseconds. Here I set it to a timeout of 1 minute.
This will set the statement_timeout
for the duration of the session. It won't effect other sessions.
You can also set the threshold with a string argument which allows you to include a unit of time. Here I set it to 30 seconds.
Now that the statement_timeout
is set to 30s
, I can run a query that I know will exceed that threshold ().
After 30 seconds have passed, the Postgres server will interrupt the query.