Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id F2C9A1337B49 for ; Fri, 17 Dec 2010 06:20:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 09139-06 for ; Fri, 17 Dec 2010 10:20:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [91.121.30.210]) by mail.postgresql.org (Postfix) with SMTP id ED4891337B61 for ; Fri, 17 Dec 2010 06:20:11 -0400 (AST) Received: (qmail 3720 invoked by uid 503); 17 Dec 2010 10:21:43 -0000 Received: from b9.ovh.net (HELO mail195.ha.ovh.net) (213.186.33.59) by 27.mail-out.ovh.net with SMTP; 17 Dec 2010 10:21:37 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 17 Dec 2010 12:20:04 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 17 Dec 2010 12:20:02 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: pgsql-performance@postgresql.org, "Royce Ausburn" Subject: Re: Auto-clustering? References: Date: Fri, 17 Dec 2010 11:20:01 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: User-Agent: Opera Mail/10.63 (Linux) X-Ovh-Tracer-Id: 4130363808653051441 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201012/209 X-Sequence-Number: 41661 > fc=# explain analyse select collection, period, tariff, sum(bytesSent), > sum(bytesReceived), sum(packets), max(sample), (starttime / 3600) * 3600 > as startchunk from sample_20101001 where starttime between 1287493200 > and 1290171599 and collection=128 and ip = '10.9.125.207' group by > startchunk, tariff, collection, > period; If CLUSTER locks bother you, and you don't do UPDATEs, you might consider doing something like this : - accumulate the rows in a "recent" table - every hour, INSERT INTO archive SELECT * FROM recent ORDER BY (your cluster fields) - DELETE FROM recent the rows you just inserted - VACUUM recent The cluster in your archive table will not be perfect but at least all rows from 1 source in 1 hour will be stored close together. But clustering doesn't need to be perfect either, if you get 100x better locality, that's already good ! Now, if you have a huge amount of data but never query it with a precision exceeding 1 hour, you might consider creating an aggregate table where, at the end of every hour, you only store sum(), min(), max() of the data for the last hour's data using GROUP BY the fields you want. You could also use a trigger, but that would generate a huge amount of UPDATEs. For the above query you'd do : INSERT INTO stats_by_hour (columns...) SELECT collection, ip, period, tariff, sum(bytesSent), sum(bytesReceived), sum(packets), max(sample), (starttime / 3600) * 3600 as startchunk from sample_20101001 WHERE starttime > some value GROUP BY collection, ip, period, tariff, startchunk Then you can run aggregates against this much smaller table instead.