From a6e108b039df4e7a12dc50e54516b4c7b0baeaf6 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 29 Oct 2010 04:34:02 +0000 Subject: [PATCH] Fix files stat under Postgres. --- Changes | 2 ++ mogstats | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 482a517..0d2be5d 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ + * Fix files stat under Postgres (Robin H. Johnson) + 2.18 -- 2010-09-28 * Add rebalance commands diff --git a/mogstats b/mogstats index 270348b..152f0c4 100755 --- a/mogstats +++ b/mogstats @@ -302,6 +302,13 @@ sub stats_for_devices { return $devs; } +sub stats_for_files_sql { + my $sql = 'SELECT dmid, classid, COUNT(classid), sum(length), sum(length::int4 * devcount::int4) FROM file GROUP BY 1, 2'; + return $sql if ($DB_TYPE eq 'Postgres'); + $sql =~ s/::int4//g; + return $sql; +} + sub stats_for_files { my $globals = shift; my %classes = %{$globals->{classes}}; @@ -309,7 +316,7 @@ sub stats_for_files { my $dbh = get_dbh() or die "Could not get database handle"; verbose("... files stats..."); - my $stats = $dbh->selectall_arrayref('SELECT dmid, classid, COUNT(classid), sum(length), sum(length * devcount) FROM file GROUP BY 1, 2'); + my $stats = $dbh->selectall_arrayref(stats_for_files_sql()); my $files = {}; for my $stat (@$stats) { my $domain = $classes{$stat->[0]}->{name};