Apache::DBI and DBD::Pg

Started by Tyler MacDonaldabout 20 years ago3 messagesgeneral
Jump to latest
#1Tyler MacDonald
tyler@yi.org

Apache::DBI claims that it will reconnect to a database if it's gone away.
DBD::Pg claims that it supports the ping method. However, when I restart my
database server while apache2 is running, all mod_perl pages that are
database driven return internal server errors, no matter how many times I
refresh, with errors like this:

[Fri Jan 13 23:46:28 2006] [error] [client 192.168.99.112] DBD::Pg::db
prepare_cached failed: FATAL: terminating connection due to administrator
command\nserver closed the connection unexpectedly\n\tThis probably means
the server terminated abnormally\n\tbefore or while processing the request.

Here's what I'm using:

DBI - 1.48
DBD::Pg - 1.42
mod_perl2 - 2.000001
Apache::DBI - 0.9901

Has anybody run into this before? Any known workarounds/config changes I
need?

Thanks,
Tyler

#2Jeremy Nixon
jeremy@exit109.com
In reply to: Tyler MacDonald (#1)
Re: Apache::DBI and DBD::Pg

Tyler MacDonald <tyler@yi.org> wrote:

[Fri Jan 13 23:46:28 2006] [error] [client 192.168.99.112] DBD::Pg::db
prepare_cached failed: FATAL: terminating connection due to administrator

Here's the thing: if your database connection goes away, and Apache::DBI
opens a new one, any prepared statement handles you might have become
invalid, because prepared statements are per-connection.

My way around it is to not use prepared statements. The only cases I have
where they would be of benefit would mean storing them across multiple
requests, and with Apache::DBI, you can't do that.

--
Jeremy | jeremy@exit109.com

#3Tim Bunce
Tim.Bunce@pobox.com
In reply to: Jeremy Nixon (#2)
Re: Apache::DBI and DBD::Pg

On Sun, Jan 15, 2006 at 02:00:15AM +0000, Jeremy Nixon wrote:

Tyler MacDonald <tyler@yi.org> wrote:

[Fri Jan 13 23:46:28 2006] [error] [client 192.168.99.112] DBD::Pg::db
prepare_cached failed: FATAL: terminating connection due to administrator

Here's the thing: if your database connection goes away, and Apache::DBI
opens a new one, any prepared statement handles you might have become
invalid, because prepared statements are per-connection.

My way around it is to not use prepared statements.

Another, better, way is to use prepare_cached() along with connect_cached().

http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/sld029.htm and later slides.

Tim.