I have no experience with anything ruby-related, let alone ActiveRecord, but a quick Google search for "postgres statement timeout" brought me to a page listing connection settings, including statement_timeout. So maybe you can find a way to increase this setting from its default value.
It might also be worth inspecting your query to see if you can optimise it a bit.
I think that's the right thought, but on that note I think decreasing the timeout value is probably more likely to be helpful I think in the macro. This seems to be a symptom of resource over-utilization where quitting early in order to avoid locking things up is probably the right course of action.
Anyway, that's where my head goes.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.