Skip to content
Permalink
Browse files

Fixes based on ollie's comments

  • Loading branch information...
mayhem committed Aug 1, 2012
1 parent 7bf6f5b commit 586c336a5e4dc3d210e0b6bfe9929af31bf60b65
Showing with 10 additions and 3 deletions.
  1. +10 −3 process-reaper/reap-long-processes.pl
@@ -7,10 +7,17 @@

use DBI;

sub kill_proc
{
my ($dbh, $pid) = @_;

$dbh->do("SELECT pg_terminate_backend(?)", undef, $pid);
}

my ($warn, $limit, $idle) = @ARGV;
my %warn_pids;

(($warn || 0) > 0 && ($idle || 0) > 0) or
(($warn || 0) > 0 && ($limit || 0) > 0 && ($idle || 0) > 0) or
die "Usage: reap-long-processes.pl <warn> <limit> <idle>
<warn> and <limit> are the amount of seconds before warning/killing processes
<idle> is the amount of time before killing idle transactions
@@ -41,15 +48,15 @@
if ($stuck->{current_query} eq "<IDLE> in transaction" && scalar(localtime) > $idle) {
printf "%s ERROR Idle in transaction process %d has been running for over %d seconds. Killing!\n",
scalar(localtime), $stuck->{procpid}, $idle;
$dbh->do("SELECT pg_terminate_backend(?)", $stuck->{procpid});
kill_proc($dbh, $stuck->{procpid});
}
}

if ($stuck->{kill}) {
printf "%s ERROR Process %d has been running for over %d seconds. Killing!\n",
scalar(localtime), $stuck->{procpid}, $limit;
printf "%s Query: %s\n", scalar(localtime), $stuck->{current_query};
$dbh->do("SELECT pg_terminate_backend(?)", $stuck->{procpid});
kill_proc($dbh, $stuck->{procpid});
}
}

0 comments on commit 586c336

Please sign in to comment.
You can’t perform that action at this time.