Skip to content

Commit d959449

Browse files
author
David Christensen
committed
Consider only client backends in query_time and friends
Should fix GH issue #139.
1 parent 798d696 commit d959449

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

check_postgres.pl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8326,7 +8326,7 @@ sub check_txn_idle {
83268326

83278327
## We don't GROUP BY because we want details on every connection
83288328
## Someday we may even break things down by database
8329-
my ($SQL2, $SQL3);
8329+
my ($SQL2, $SQL3, $SQL4);
83308330
if ($type ne 'qtime') {
83318331
$SQL = q{SELECT datname, datid, procpid AS pid, usename, client_addr, xact_start, current_query AS current_query, '' AS state, }.
83328332
q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }.
@@ -8358,7 +8358,10 @@ sub check_txn_idle {
83588358
$SQL3 =~ s/'' AS state/state AS state/;
83598359
$SQL3 =~ s/query_start/state_change/g;
83608360

8361-
my $info = run_command($SQL, { emptyok => 1 , version => [ "<8.3 $SQL2", ">9.1 $SQL3" ] } );
8361+
## For Pg 10 and above, consider only client backends
8362+
($SQL4 = $SQL3) =~ s/ WHERE / WHERE backend_type = 'client backend' AND /;
8363+
8364+
my $info = run_command($SQL, { emptyok => 1 , version => [ "<8.3 $SQL2", ">9.1 $SQL3", ">10 $SQL4" ] } );
83628365

83638366
## Extract the first entry
83648367
$db = $info->{db}[0];

0 commit comments

Comments
 (0)