Extra database connections hanging around

Our Rails app has a lot of Postgres processes, way more than the number
of Rails server processes. It hits the limit we’ve set on connections
for Postgres. Why is this happening?

We’ve got seven Rails processes running (using Lighttpd & FCGI). After
Rails has been up for a few days, we have > 25 Postgres connection
processes.
Most of them look idle. We’re not using multiple databases or
class-specific
connections. I thought Rails only uses one connection per application
instance; is this correct?

Using lsof to do some digging, they’re all established connected with a
dispatch.fcgi process. One of the dispatch.fcgi processes has four open
connections!

We do occasionally run command-line programs that require ActiveRecord
to bulk load data. I thought maybe this would be a problem since I don’t
explicitly close the connection on program exit, but after testing, this
doesn’t appear to be the problem. It doesn’t leave a persistent
connection, and all the connections are connected to dispatch processes.

Any ideas what’s going on?

Thanks

[Rails 1.1.6; Postgres 8.1.4]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs