Set Statement Timeout For All Postgres Connections
The statement_timeout
setting in PostgreSQL allows you to head off long running queries and migrations that could break your deploys and lock up your production tables.
This value can be set to a sensible default across all the connections your Rails app makes to PostgreSQL. To set it, open up your config/database.yml
file and add a variables
element to the default section.
That's 60 seconds in milliseconds. You can avoid the mental math by using a string argument with a unit such as s
for seconds.
If you then execute a long running query, such as:
It will terminate 2 seconds early because of the statement timeout.
Last updated