How to properly setup multiple databases?

I’ve setup my application to connect to multiple databases, but am
running
into a few issues in production. I also have a few questions.

First, I’m using rails 3-2-stable, because I was running in to a
prepared
statement bug, which is only fixed in this branch [1]. I’m not up for
using master at this time, unless I absolutely need to.

Second, the pool size for the default and non-default database is 1,
this
is because I’m using unicorn. Also, because establish_connection on
multiple databases does not use the pool size [2].

The issue:

I have 4 unicorn workers. After I start the app and rapidly refresh on
a
few pages, the default database sees 4 connections. The non-default
database sees only 1. And for the lifetime of the app, the non-default
database only sees one connection. I also think this is slowing down the
website.

  1. What would cause the application to create only one connection for
    the
    non-default database, provided I have 4 workers? When I create a sample
    app on my local machine that uses the same configs with different code,
    I
    actually get 4 connections for both. See my unicorn file here:
    Unicorn Config · GitHub. All my non-default database models
    inherit from something that looks like:

class OtherDb < ActiveRecord::Base
self.abstract_class = true
establish_connection “other_#{Rails.env}”
end

  1. What’s the proper way to setup a unicorn.rb file for multiple
    databases
    with preload_app true, since I have establish_connection in the
    OtherDb
    model and need to establish_connection to the default in the after_fork?

  2. Should I be looking into a different rack web server? My queries are
    sub 500ms.

[1] Remove prepared statement from system query in postgresql adapter by evtuhovich · Pull Request #5872 · rails/rails · GitHub
[2] ActiveRecord::Base.establish_connection does not use the connection pool · Issue #7019 · rails/rails · GitHub