Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a much shorter time for killing idle in transaction procs
- Loading branch information
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong.
ocharles
Contributor
|
||
} | ||
} | ||
|
||
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.
Sorry, something went wrong.
ocharles
Contributor
|
||
} | ||
} | ||
|
||
|
You want to check
$warn
,$idle
and$limit
are all >0 (you've removed the test for$limit
.