On 04/09/2011 03:58, Mr. Puneet Kishor wrote:
On Sep 3, 2011, at 9:46 PM, David E. Wheeler wrote:
On Sep 3, 2011, at 7:27 PM, Mr. Puneet Kishor wrote:
I am on Mac OS X Lion with Pg 9.0.x, Perl 5.14.1, and the latest iterations of
DBI and DBD::Pg. My code is pretty straightforward
my $dbh = DBI->connect("dbi:Pg:dbname=macromap;host=localhost;port=5432",
'postgres', 'postgres');
my $sth = $dbh->prepare( .. );
$sth->execute;
while (my (retrieved columns) = $sth->fetchrow_array) {
do something with retrieved columns
}
The code bombs with the message:
DBD::Pg::st execute failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request. at ...
IIRC, I've seen that when the back end had segfaulted. What do you see in your
PostgreSQL log?
The only line of interest I can see is 'LOG: unexpected EOF on client
connection'
On a related note, I am finding that this is possibly because $dbh is getting
automatically closed. From the docs:
"InactiveDestroy (boolean)
If set to true, then the "disconnect" method will not be automatically called when
the database handle goes out of scope. "
So, I am recreating $dbh, and it seems to be working. Would like to know
though, how and why the dbh is getting disconnected.
InactiveDestroy applies to the handle going out of scope e.g., if you
fork and want the child process to use the handle but it goes out of
scope in the parent, DBI will normally close the connection and setting
InactiveDestroy stops it doing that.
Martin