title: Gracefully force database reconnection in Rails 4
body: <p>We have a Rails 4 app that uses a database that sometimes gets updated by having a new instance of the database spun up and then ops updates the DNS record to point to the new instance (not ideal, but I can't change that).  The problem is that the Rails connection pool still keeps its connections open to the <em>old</em> database and won't talk to the <em>new</em> database unless we restart Rails.  We can do that, but it's a pain.  </p>
  
  <p>We would like to have an administrative endpoint we could hit that tells the app to gracefully close database connections and restart.  <code>ActiveRecord::Base.connection_pool.disconnect!</code> certainly closes the old database connections and when new ones are requested, they talk to the new instance, but it also takes a shotgun to any running queries and terminates them rather than letting them finish.</p>
  
  <p>Is there a way to tell Rails to refresh all of its database connections at runtime in a way that will allow currently running queries to finish before being closed?</p>