postgres Database Pg module

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

From: Kemin Zhou
Subject: postgres Database Pg module
Date: 21:31 on 14 Feb 2005
This is a multi-part message in MIME format.
--------------020203070704050301000300
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Friends,
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? 

When using Pg I run into such problems as when the connection reaches 
the limit, no more connection
can be made.  This can be seen on the server that host the postgres server

ps -ef | grep postgres

will show all the idle postgres processes.

To overcome this problem I simply did this in my perl script

#!/usr/bin/perl -w

use Apache::Request;
use Pg;

# here I am using the same username and password for all of my
# scripts

my $dbuser="dbreader";
my $passwd="a_secret_str";

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

This seems to work, which means that the number of idle postgres 
processes on the server does not
accumulate to the point that no more connection can be made.  I am not 
sure this solution is
to good to be "true".

Am I doing the right thing?  If I am using the same username and 
password for all of my scripts
on the http server, will this cause problems? 

Apache::DBI seems to take care of all of my problems. 

Thanks.

Kemin



--------------020203070704050301000300
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffcc" text="#000000">
Hi Friends,<br>
I am using mod_perl 2.&nbsp; I question about database connections.<br>
I use the Pg module to connect to the backend.&nbsp; Could you tell me that
this is not a good idea and<br>
I should have used Apache::DBI?&nbsp; <br>
<br>
When using Pg I run into such problems as when the connection reaches
the limit, no more connection<br>
can be made.&nbsp; This can be seen on the server that host the postgres
server<br>
<br>
ps -ef | grep postgres<br>
<br>
will show all the idle postgres processes.<br>
<br>
To overcome this problem I simply did this in my perl script<br>
<br>
#!/usr/bin/perl -w<br>
<br>
use Apache::Request;<br>
use Pg;<br>
<br>
# here I am using the same username and password for all of my <br>
# scripts<br>
<br>
my $dbuser="dbreader";<br>
my $passwd="a_secret_str";<br>
<br>
our $pgdb;<br>
if (!$pgdb) {<br>
&nbsp;&nbsp;&nbsp; $pgdb = Pg::connectdb("host=localhost dbname=$mydb user=$dbuser
password=$passwd");<br>
}<br>
<br>
This seems to work, which means that the number of idle postgres
processes on the server does not<br>
accumulate to the point that no more connection can be made.&nbsp; I am not
sure this solution is<br>
to good to be "true".<br>
<br>
Am I doing the right thing?&nbsp; If I am using the same username and
password for all of my scripts<br>
on the http server, will this cause problems?&nbsp; <br>
<br>
Apache::DBI seems to take care of all of my problems.&nbsp; <br>
<br>
Thanks.<br>
<br>
Kemin<br>
<br>
<br>
</body>
</html>

--------------020203070704050301000300--

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