On Mon, Oct 13, 2008 at 10:29 AM, Deviloper <[EMAIL PROTECTED]> wrote:
> Hi there, > > in the early days of the dbi-modul there was a function $dbh->ping(). > nearly no driver ever implemented it. > > I want to check the status of my db, in my daemon on a regular base. > I could not find any standard solution. Today I´m just doing a query > and check then if there where errors. > > > Also I want to reread the DB config. > (My Daemons are running stable for years, but the DB-Guy switch from one db > to another > on a weekly base and I just wont care if my configfile is reread.) > > > I do it this way :(RaiseErrors is off) > > my $sth = $dbh->prepare("$query"); > > $sth->execute(); > > # $sth->finish(); #not needed with autocommit > > if ( defined $DBI::errstr || defined $sth->errstr()){ > # close db. > #... reread configurationfile and > # connect with new config. > } > I would start by hitting the DB-guy over the head for being such a pain in the butt. :-) Then I think that the only real way to make certain that your database handle still is valid is by periodicaly executing a query and checking the result to make sure just like you are doing. The problem with the $dbh->ping() is that it usualy ends up not hitting the actual database but returns a result from the listening service, this confirms that that process is active but does not mean that your database is actually able to process any queries for modren databases. Then there are of course the databases that do not support such a command at all which makes the $dbh->ping() a unreliable way of checking if a database handle is good. I think what you are doing is pretty much the safest and most reliable way of validating a database handle. The only thing that you need to make sure of is that you make the query as fast as possible, all major databases have a simple query that will always return the same value usualy a select from a single column single row table or from a constant value. For Oracle and Mysql for instance this is: select * from dual; Where Sybase likes select 1 from dummy better.