Hi, I''ve got an activerecord query which takes longer than 100 seconds. I''m using rails 2.2 with postgresql 8.3. http://www.postgresql.org/docs/8.3/static/runtime-config-client.html mentions an option called "statement_timeout" which when set aborts a query which takes longer than x milli seconds. How do I pass this option to AR so that it in turn passes this to postgresql? cheers, skar. -- -- The life so short, the craft so long to learn.
You''ve probably already figured it out, but this looks workable: # See this page for some of the statement-related settings: # http://www.postgresql.org/docs/8.3/static/runtime-config-client.html def setStatementTimeout milliseconds query = "SET statement_timeout = #{milliseconds};" ActiveRecord::Base.connection().execute query end On Sep 25, 6:13 am, skar <skar.karthike...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''ve got an activerecord query which takes longer than 100 seconds. I''m > using rails 2.2 with postgresql 8.3.http://www.postgresql.org/docs/8.3/static/runtime-config-client.html > mentions an option called "statement_timeout" which when set aborts a > query which takes longer than x milli seconds. > > How do I pass this option to AR so that it in turn passes this to > postgresql? > > cheers, > skar. > > -- > -- > The life so short, the craft so long to learn.
Another alternative would be to just wrap your long-running query in a timeout, something like: require ''timeout'' ... begin status = Timeout::timeout(60) do # some long-running action .... end rescue Timeout::Error => te # .... end Jeff On Oct 13, 1:07 pm, JohnB <john.bay...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You''ve probably already figured it out, but this looks workable: > > # See this page for some of the statement-related settings: > # http://www.postgresql.org/docs/8.3/static/runtime-config-client.html > def setStatementTimeout milliseconds > query = "SET statement_timeout = #{milliseconds};" > ActiveRecord::Base.connection().execute query > end > > On Sep 25, 6:13 am, skar <skar.karthike...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > I''ve got an activerecord query which takes longer than 100 seconds. I''m > > using rails 2.2 with postgresql 8.3.http://www.postgresql.org/docs/8.3/static/runtime-config-client.html > > mentions an option called "statement_timeout" which when set aborts a > > query which takes longer than x milli seconds. > > > How do I pass this option to AR so that it in turn passes this to > > postgresql? > > > cheers, > > skar. > > > -- > > -- > > The life so short, the craft so long to learn.
anthonyeden-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Dec-09 23:27 UTC
Re: how to time out a query
This will result in the query continuing to run on the database though, thus consuming resources, which may not be something you want. Sincerely, Anthony Eden On Oct 13, 7:32 pm, Jeff Lewis <jeff.bu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Another alternative would be to just wrap your long-running query in a > timeout, something like: > > require ''timeout'' > ... > begin > status = Timeout::timeout(60) do > # some long-running action .... > end > rescue Timeout::Error => te > # .... > end > > Jeff > > On Oct 13, 1:07 pm, JohnB <john.bay...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > You''ve probably already figured it out, but this looks workable: > > > # See this page for some of the statement-related settings: > > # http://www.postgresql.org/docs/8.3/static/runtime-config-client.html > > def setStatementTimeout milliseconds > > query = "SET statement_timeout = #{milliseconds};" > > ActiveRecord::Base.connection().execute query > > end > > > On Sep 25, 6:13 am, skar <skar.karthike...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > I''ve got an activerecord query which takes longer than 100 seconds. I''m > > > using rails 2.2 with postgresql 8.3.http://www.postgresql.org/docs/8.3/static/runtime-config-client.html > > > mentions an option called "statement_timeout" which when set aborts a > > > query which takes longer than x milli seconds. > > > > How do I pass this option to AR so that it in turn passes this to > > > postgresql? > > > > cheers, > > > skar. > > > > -- > > > -- > > > The life so short, the craft so long to learn.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.