how to set postgresql command timeout in rails

后端 未结 4 721
梦谈多话
梦谈多话 2021-02-07 08:11

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?

4条回答
  •  北海茫月
    2021-02-07 08:53

    Adding

    ActiveRecord::Base.connection.execute('set statement_timeout to 10000')
    

    to the end of the environment.rb file did not work for me.

    What worked was adding

    ActiveRecord::Base.connection.execute("SET statement_timeout = '10s'")
    

    to an initialize file.

提交回复
热议问题