-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

> Ima::DBI and DBIx::Class::Storage::DBI both call ping() to check if
> the database is alive before retuning a cached $dbh.
>
> I'm curious if this is a smart approach for a very database-heavy
> site, or if this might be a hold-over from the "morning after" problem
> where site that were quiet all night would fail in the morning as
> their connections had timed out.

It's a bad strategy no matter what the reasoning. Applications should
simply do things as normal and handle exceptions in a sensible matter.
That said, $dbh->ping() is about as low intensity as one can get and
still get a reasonable snapshot on the health of the database. For
DBD::Pg, we (in C/XS) check the current libpq status. If it's bad,
we return it as bad right away. If libpq think it's good, we issue
a simple SELECT query anyway, as we can't be sure libpq has the correct
status. As long as you aren't calling ping() too often (e.g. before
every query), it's generally fine to use.

I realize that this is out of the scope of abstractions like DBIx::Class,
but it's better to use $dbh->pg_ping(), as it returns a little more
information than the boolean yes/no of $dbh->ping().

- --
Greg Sabino Mullane [email protected]
End Point Corporation
PGP Key: 0x14964AC8 200904282229
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAkn3u94ACgkQvJuQZxSWSsgnwACgpY/lBMUasMQHYoVMA8/VcQ/K
2uwAoPmZ74uzTNisqvvINKUxWXaQM25z
=9CZo
-----END PGP SIGNATURE-----


Reply via email to