I'm using heroku and heroku postgresql. How do I set db command timeout so that I get an exception when a sql command takes longer than 10 seconds?
Configure your database.yml like this, the key bit being the variables hash:
defaults: &default
adapter: postgresql
encoding: unicode
pool: 5
min_messages: warning
variables:
statement_timeout: 5000
I found a solution here: Ruby on Rails: How to set a database timeout in application configuration?
Add
ActiveRecord::Base.connection.execute('set statement_timeout to 10000')
in the end of the environment.rb
file.
Does anyone see a better way?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With