From: Greg Sabino Mullane Date: Wed, 1 May 2013 01:35:55 +0000 (-0400) Subject: Do things the right way and run different versions of the bloat query depending on... X-Git-Tag: 2.20.1~15 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=b55b3ef0b1371e56f4946795359dd321881bffbe;p=check_postgres.git Do things the right way and run different versions of the bloat query depending on the target version. --- diff --git a/check_postgres.pl b/check_postgres.pl index c7c777f49..85f7fef71 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -3574,7 +3574,7 @@ FROM ( AND s.attname=att.attname, ( SELECT - BLOCK_SIZE, + (SELECT current_setting('block_size')::numeric) AS bs, CASE WHEN SUBSTRING(SPLIT_PART(v, ' ', 2) FROM '#"[0-9]+.[0-9]+#"%' for '#') IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr, CASE WHEN v ~ 'mingw32' OR v ~ '64-bit' THEN 8 ELSE 4 END AS ma @@ -3598,18 +3598,18 @@ FROM ( $SQL .= ' ORDER BY totalwastedbytes DESC'; } - if ($psql_version <= 7.4) { - $SQL =~ s/BLOCK_SIZE/(SELECT 8192) AS bs/; - } - else { - $SQL =~ s/BLOCK_SIZE/(SELECT current_setting('block_size')::numeric) AS bs/; + ## Alternate versions for old versions + my $SQL2 = $SQL; + if ($psql_version <= 8.4) { + $SQL2 =~ s/AND s.inherited=false//; } - if ($psql_version <= 8.4) { - $SQL =~ s/AND s.inherited=false//; + my $SQL3 = $SQL2; + if ($psql_version <= 7.4) { + $SQL3 =~ s/SELECT current_setting.+?AS bs/(SELECT 8192) AS bs/; } - my $info = run_command($SQL); + my $info = run_command($SQL, { version => [ "<8.0 $SQL3", "<9.0 $SQL2" ] } ); if (defined $info->{db}[0] and exists $info->{db}[0]{error}) { ndie $info->{db}[0]{error};