From 6facd3c33183820b13da40cb962dc2f9dee5eb76 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 14 Mar 2012 17:26:15 +0900 Subject: [PATCH] die commands if no DB connection can be made graceful die script if DB connection cannot be created. Also for prepare & execute command --- plugins/postgresql/pgbouncer_ | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/postgresql/pgbouncer_ b/plugins/postgresql/pgbouncer_ index 208d663e..610c4834 100755 --- a/plugins/postgresql/pgbouncer_ +++ b/plugins/postgresql/pgbouncer_ @@ -157,13 +157,16 @@ if (defined($ARGV[0])) } # connect to data -my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass); +my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass) + or die ("Cannot connect to database"); # go trough each set and get the data foreach my $get ('pools', 'stats') { # prep and execute the show query - my $pre = $dbh->prepare("SHOW $get"); - $pre->execute(); + my $pre = $dbh->prepare("SHOW $get") + or die ("Cannot prepare query"); + $pre->execute() + or die ("Cannot execute statement") while (@data = $pre->fetchrow) { # first defines the pool