[Catalyst] Shared database handles

Toby Corkindale toby at ymogen.net
Mon May 8 12:28:02 CEST 2006


Eduardo Anuel wrote:
> Hi, my name is Eduardo Anuel, I've been using catalyst on a web
> application since three months ago, about two weeks ago I decided to
> put the application on apache using mod_perl and I started getting
> weird errors with the database, snooping around this list I found
> somebody who had a similar problem, this is the thread:
> http://www.gossamer-threads.com/lists/catalyst/users/2324#2324 .
> 
> There is an explanation to the issue there and a solution for Class
> DBI, but sadly in my application I use mostly pure DBI with the
> Catalyst::Model::DBI module, I tried to adapt the solution for CDBI to
> my Model on DBI but I hasn't been able to acomplish it, if anybody has
> any thoughts about it or knows how can I work around this problem I
> would really appreciate your help.

Hi,
This occurs because you're connecting to the DB once, during Apache 
startup, and then continuuing to use the same DB handle in all the 
fork()ed children too.

To see what I mean, try doing "ps auxw|grep postgres" and noticing that 
you probably only have one connection to your database.
Now run "ps auxw|grep "httpd|apache"" and notice that you have probably 
half a dozen or more apache processes..

You fix this by making sure you disconnect from the database after your 
initial setup, and then reconnecting in each child.

If you're using a modern Class::DBI or DBIx::Class setup with Catalyst 
then it'll do that for you. If you're using pure DBI, then do something 
like this in your main library: Disconnect from the DB, then reconnect.

I know it sounds odd, but it'll sort you out.

It will cause each child to disconnect from it's (inherited, shared) DB 
handle, and then reconnect and get it's own unique handle.

-Toby

> --
> Think for yourself...Question Authority
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
> 




More information about the Catalyst mailing list