Skip to content
Permalink
Browse files

Added a much shorter time for killing idle in transaction procs

  • Loading branch information...
mayhem committed Aug 1, 2012
1 parent 561b287 commit 7bf6f5bdd7d20ccaa650d1539296a3e240bb1d0a
Showing with 10 additions and 4 deletions.
  1. +10 −4 process-reaper/reap-long-processes.pl
@@ -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')
@@ -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})

}
}

0 comments on commit 7bf6f5b

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