Robust Method For Testing Database Handles

From: Keg (rhugga_at_yahoo.com)
Date: 04/21/04


Date: 21 Apr 2004 07:09:44 -0700

Hey all,

Trying to determine a reliable, rock-solid, low-cost method of testing
a database handle.

If the database is down or the connection fails or anything that will
cause operations on a database handle to fail, will my database handle
be undefined then? I wonder because the following code gives me
inconsistent results when the system load gets high:

if (!defined($dbh1)) {
....

Is this a rock solid way of testing your database connection? Does
anyone use $dbh1->ping??? The documentation says that unless you know
for sure you need to use the ping() method, you likely don't.

Basically I have a daemon written in perl that runs 24/7 and analyzes
various processes and logs information to a mysql database. Inside my
main loop I check the database handle each iteration and if it is
down, I spin until a connection can be re-established. However, my
problem lies in the testing of the connection and how to properly do
this.

I can't afford to disconnect and reconnect, this is a very
high-throughput process. I also want to avoid using a SQL query just
to test if the database handle is still valid or not.

My environment is RH 9 running a vanilla 2.4.20-28.9smp kernel, a
vanilla build of mysql-max-4.0.18, perl DBI 1.42, DBD::mysql 2.9003,
and vanilla perl 5.8.

Thx,
Keg



Relevant Pages

  • Re: ADO Connection Timeout
    ... so what happens when a connection failure forces one station to revert ... to a local database? ... Further, you *will* have contention issues, Jet does not support record ... to the central server, but you are willing to live with periods where it ...
    (microsoft.public.data.ado)
  • ANN: Sequel 3.11.0 Released
    ... Sequel is a lightweight database access toolkit for Ruby. ... Sequel provides thread safety, connection pooling and a concise DSL ... for constructing database queries and table schemas. ...
    (comp.lang.ruby)
  • ANN: Sequel 3.9.0 Released
    ... Sequel is a lightweight database access toolkit for Ruby. ... Sequel provides thread safety, connection pooling and a concise DSL ... the default connection pool no longer contains ...
    (comp.lang.ruby)
  • Re: ADO Connection Timeout
    ... When the first test is run, the results are stored in the central database. ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)
  • Re: ADO Connection Timeout
    ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)