Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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?

Replies are listed 'Best First'.
Re: alarm in DBI module
by salva (Abbot) 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 (Curate) on Sep 08, 2010 at 16:08 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://858153]
Approved by salva
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-05-22 02:51 GMT
Find Nodes?
    Voting Booth?