Re: postgres Database Pg module

[prev] [thread] [next] [Date index for 2005/02/14]

From: Perrin Harkins
Subject: Re: postgres Database Pg module
Date: 22:50 on 14 Feb 2005
On Mon, 2005-02-14 at 13:31 -0800, Kemin Zhou wrote:
> I am using mod_perl 2.  I question about database connections.
> I use the Pg module to connect to the backend.  Could you tell me that
> this is not a good idea and
> I should have used Apache::DBI?  


Apache::DBI is used to make your Pg connection persistent.  It's not a
choice between one or the other.

> When using Pg I run into such problems as when the connection reaches
> the limit, no more connection
> can be made.

You'll need to either raise the limit or reduce the number of
connections.  Make sure you are not serving static pages or images
through mod_perl by running a reverse proxy.  There are details about
this in the mod_perl documentation.

> our $pgdb;
> if (!$pgdb) {
>     $pgdb = Pg::connectdb("host=localhost dbname=$mydb user=$dbuser
> password=$passwd");
> }

That's what Apache::DBI does for you.  It also does an automatic
rollback of any uncommitted work at the end of each request.  This will
save you from getting stuck if your code dies part-way through a
transaction.

- Perrin

postgres Database Pg module
Kemin Zhou 21:31 on 14 Feb 2005

Re: postgres Database Pg module
Perrin Harkins 22:50 on 14 Feb 2005

Generated at 12:48 on 22 Feb 2005 by mariachi v0.52