[Feature Proposal] ActiveRecord Connection Lifetime (Age)

I know this is an old thread, but this functionality is a requirement if you’re running e.g. PgBouncer in session mode and need to PAUSE in order to fail-over one’s database without downtime. Clearly the Rails devs agreed, since this now exists in Rails v8.1. That doesn’t help those of us who aren’t using Rails v8.1 yet, though.

We have a number of projects, some of which are quite old, but we’d like to be able to run them against a pooler as well. If anyone else is in the same boat, we published a backport of this functionality as a gem named activerecord_connection_reaper. Just add it to your gemfile and your Rails app (all the way back to Ruby v2.5 and Rails v5.1) will support max_age, pool_jitter, and reaping_frequency, just like Rails v8.1 does. Hope it’s useful.