diff options
author | Jehan-Guillaume (ioguix) de Rorthais | 2011-10-04 19:40:53 +0000 |
---|---|---|
committer | Guillaume Lelarge | 2011-10-04 19:40:53 +0000 |
commit | 872aa96d371a7f07b6d78525dcaa99aff98fbf83 (patch) | |
tree | a54b296c97f0cc2af0753d9108b29c828b7c49b4 /check_postgres.pl | |
parent | 0e1cb6bea1b011f0a3f779cd5414fc36573ae2d4 (diff) |
Fix query time action
The query_time action works before 8.1 if the query doesn't include the
xact_start column. But we need this column for the txn_time action. So, I
changed the query so that the query_time can work with 8.1 and upwards, and
that the txn_time works with 8.3 and upwards.
Diffstat (limited to 'check_postgres.pl')
-rwxr-xr-x | check_postgres.pl | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/check_postgres.pl b/check_postgres.pl index e05e5539c..b741583ff 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -1681,7 +1681,7 @@ our %testaction = ( sequence => 'VERSION: 8.1', table_size => 'VERSION: 8.1', index_size => 'VERSION: 8.1', - query_time => 'VERSION: 8.3', + query_time => 'VERSION: 8.1', txn_idle => 'VERSION: 8.3', txn_time => 'VERSION: 8.3', wal_files => 'VERSION: 8.1', @@ -7236,14 +7236,24 @@ sub check_txn_idle { ## We don't GROUP BY because we want details on every connection ## Someday we may even break things down by database - $SQL = q{SELECT datname, datid, procpid, usename, client_addr, xact_start, current_query, }. - q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }. - qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }. - qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }. - qq{ORDER BY xact_start, query_start, procpid DESC}; + if ($type ne "qtime") { + $SQL = q{SELECT datname, datid, procpid, usename, client_addr, xact_start, current_query, }. + q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }. + qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }. + qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }. + qq{ORDER BY xact_start, query_start, procpid DESC}; + } + else { + $SQL = q{SELECT datname, datid, procpid, usename, client_addr, current_query, }. + q{CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, }. + qq{COALESCE(ROUND(EXTRACT(epoch FROM now()-$start)),0) AS seconds }. + qq{FROM pg_stat_activity WHERE $clause$USERWHERECLAUSE }. + qq{ORDER BY query_start, procpid DESC}; + } my $info = run_command($SQL, { emptyok => 1 } ); + ## Extract the first entry $db = $info->{db}[0]; @@ -7278,7 +7288,7 @@ sub check_txn_idle { } ## Detect other cases where pg_stat_activity is not fully populated - if (length $r->{xact_start} and $r->{xact_start} !~ /\d/o) { + if ($type ne "qtime" and length $r->{xact_start} and $r->{xact_start} !~ /\d/o) { add_unknown msg('psa-noexact'); return; } @@ -8786,7 +8796,7 @@ are 'seconds', 'minutes', 'hours', or 'days'. Each may be written singular or abbreviated to just the first letter. If no units are given, the unit is assumed to be seconds. -This action requires Postgres 8.3 or better. +This action requires Postgres 8.1 or better. Example 1: Give a warning if any query has been running longer than 3 minutes, and a critical if longer than 5 minutes. |