Skip to content

Commit

Permalink
Added a much shorter time for killing idle in transaction procs
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhem committed Aug 1, 2012
1 parent 561b287 commit 7bf6f5b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions process-reaper/reap-long-processes.pl
Expand Up @@ -7,12 +7,13 @@

use DBI;

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

(($warn || 0) > 0 && ($limit || 0) > 0) or
die "Usage: reap-long-processes.pl <warn> <limit>
(($warn || 0) > 0 && ($idle || 0) > 0) or

This comment has been minimized.

Copy link
@ocharles

ocharles Aug 1, 2012

Contributor

You want to check $warn, $idle and $limit are all >0 (you've removed the test for $limit.

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
";

my $dbh = DBI->connect('dbi:Pg:dbname=postgres;host=127.0.0.1', 'postgres')
Expand All @@ -37,13 +38,18 @@
scalar(localtime), $stuck->{procpid}, $warn;
printf "%s Query: %s\n", scalar(localtime), $stuck->{current_query};
$warn_pids{$stuck->{procpid}} = $stuck->{query_start};
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});

This comment has been minimized.

Copy link
@ocharles

ocharles Aug 1, 2012

Contributor

Ditto with my comment on this bellow. Probably worth factoring out what it means to do a kill into a subroutine.

}
}

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};
kill(15, $stuck->{procpid});
$dbh->do("SELECT pg_terminate_backend(?)", $stuck->{procpid});

This comment has been minimized.

Copy link
@ocharles

ocharles Aug 1, 2012

Contributor

This is a DBI object, not one of our Sql objects. do is $dbh->do($statement, \%attr, @bind_values), so you want $dbh->do('SELECT pg_terminate_backend(?)', undef, $stuck->{procpid})

}
}

Expand Down

0 comments on commit 7bf6f5b

Please sign in to comment.