Discussion:
Postgres Timeout For Statements
Samuel Reh
2015-04-15 18:06:00 UTC
Permalink
I have a problem where some of my queries run way too long. Obviously, the
long term solution is to fix the slow queries, but for now I'd like to use
some sort of timeout for when this happens. Currently I log in and run
`select pg_terminate_backend(pid)`.

I'm using the PG gem and the Threaded connection pool.

Is there a way for Sequel to kill these connections (or better yet, put
them in an idle state so they become available in the pool)? Or should I be
using pg_bouncer for this kind of stuff?

Thanks,
Sam
--
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+***@googlegroups.com.
To post to this group, send email to sequel-***@googlegroups.com.
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.
Jeremy Evans
2015-04-15 19:27:09 UTC
Permalink
Post by Samuel Reh
I have a problem where some of my queries run way too long. Obviously, the
long term solution is to fix the slow queries, but for now I'd like to use
some sort of timeout for when this happens. Currently I log in and run
`select pg_terminate_backend(pid)`.
I'm using the PG gem and the Threaded connection pool.
Is there a way for Sequel to kill these connections (or better yet, put
them in an idle state so they become available in the pool)? Or should I be
using pg_bouncer for this kind of stuff?
PostgreSQL supports setting a statement timeout per connection, so you can
use an after_connect proc to set it for all connections that Sequel creates:

DB = Sequel.connect('postgres://...', :after_connect=>proc{|c|
c.execute('SET statement_timeout = 1000')}) # one second

Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+***@googlegroups.com.
To post to this group, send email to sequel-***@googlegroups.com.
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.
Loading...