Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set postgresql command timeout in rails

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?

like image 725
Clark Avatar asked Feb 07 '13 00:02

Clark


2 Answers

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
like image 186
Bill Lipa Avatar answered Sep 28 '22 18:09

Bill Lipa


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?

like image 32
Clark Avatar answered Sep 28 '22 16:09

Clark