title: Rails+PostgreSQL: search_path depending on subdomain
body: <p>In our rails 2.x application the <code>search_path</code> of the database connection depends on the subdomain through which the application is contacted (basically <code>search_path = "production_"+subdomain</code>). Because the <code>search_path</code> is defined per connection and database connections are shared over requests, even concurrently, this is a problem. I would rather not change concurrency to only serve one request at a time for obvious reasons.</p>
  
  <p>So is there a way to group the database connections in the connection pool and set some kind of policy that only a fitting connection is used for the request? Or is there a way to use one connection pool per subdomain (where the pools are automatically discarded after a timeout)? Starting a rails instance for each subdomain is no option because there might be many idling subdomains (it's some kind of pro-account where you get a subdomain and your own "world" that differs from the rest of the site in some tables).</p>
  
  <p>What would be the best solution for this problem?</p>