May 2018
Intermediate to advanced
576 pages
30h 25m
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 others' queries fail.
The queries terminated by a statement timeout show up in the log, as follows:
hannu=# SET statement_timeout TO '3 s';SEThannu=# SELECT pg_sleep(10);ERROR: canceling statement ...