how to set postgresql command timeout in rails

后端 未结 4 880
梦谈多话
梦谈多话 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:37

    I don't know ruby, but in PostgreSQL you can simply run this:

    SET statement_timeout = '10s'
    

    and afterwards, all queries in this connection (session) will have strict limit on runtime.

    You can also change it in postgresql.conf as global default, or even make it default in given database or for given user like:

    ALTER DATABASE web SET statement_timeout = '10s';
    ALTER USER bad_user SET statement_timeout = '10s';
    

提交回复
热议问题