Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

alarm in DBI module

by vetrivel (Sexton)
on Aug 31, 2010 at 11:09 UTC ( #858153=perlquestion: print w/ replies, xml ) Need Help??
vetrivel has asked for the wisdom of the Perl Monks concerning the following question:

Hai , I am using DBI module to connect with postgres data base .

$SIG{ALRM} = sub { print "Alarm Captured" ; exit ; } ; alarm 10 ; DBI->connect(...) alarm 0 ;

My postgresql server is down . If I run the above code , DBI gives me an error after 20 seconds . In this case , Alarm is not captured . But I required alarm should be executecd . Is alarm useful only for IO Interuppt?

Comment on alarm in DBI module
Download Code
Re: alarm in DBI module
by salva (Monsignor) on Aug 31, 2010 at 11:54 UTC
    As the postgres client library allows to set a timeout for the connecting stage, the implementation of that feature may interfere with any timer previously set from the caller code.

    You can change the default timeout (15s) on the DBI connection string as follows:

    my $dbh = DBI->connect("dbi:Pg:dbname=$db_name;host=$db_host;connect_t +imeout=$db_connect_timeout", ...);
Re: alarm in DBI module
by jethro (Monsignor) on Aug 31, 2010 at 12:10 UTC
    Please don't use <pre> tags for code, they don't wrap text. Use <code> tags instead. With 23 posts published you already should know that. See Writeup Formatting Tips
Re: alarm in DBI module
by vek (Prior) on Aug 31, 2010 at 19:53 UTC

    I absolutely cannot recommend Sys::SigAction enough. I use it successfully in production with MySQL. Go give it a try and let us know if you're still having issues. I suspect you won't.

Re: alarm in DBI module
by mje (Deacon) on Sep 08, 2010 at 16:08 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://858153]
Approved by salva
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-07-29 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls