May 2019
Intermediate to advanced
600 pages
20h 46m
English
Often, you know that you don't have any use for queries running longer than a given time. Maybe your web frontend just refuses to wait for more than 10 seconds for a query to complete and returns a default answer to users if it takes longer, abandoning the query.
In such a case, it might be a good idea to set statement_timeout = 10 sec, either in postgresql.conf or as a per-user or per-database setting. Once you do so, queries running too long won't consume precious resources and make other queries fail.
The queries terminated by a statement timeout show up in the log, as follows:
postgres=# SET statement_timeout TO '3 s';SETpostgres=# SELECT pg_sleep(10);ERROR: canceling ...
Read now
Unlock full access