Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 922FD63259B for ; Sat, 9 Jan 2010 11:37:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 45860-03 for ; Sat, 9 Jan 2010 15:37:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 63.mail-out.ovh.net (63.mail-out.ovh.net [91.121.185.56]) by mail.postgresql.org (Postfix) with SMTP id C1C4F63235F for ; Sat, 9 Jan 2010 11:37:01 -0400 (AST) Received: (qmail 17840 invoked by uid 503); 9 Jan 2010 15:37:30 -0000 Received: from b6.ovh.net (HELO mail609.ha.ovh.net) (213.186.33.56) by 63.mail-out.ovh.net with SMTP; 9 Jan 2010 15:37:30 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 9 Jan 2010 15:36:58 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO soyouz) (88.161.102.87) by ns0.ovh.net with SMTP; 9 Jan 2010 15:36:56 -0000 Date: Sat, 09 Jan 2010 16:37:29 +0100 To: Nickolay , "Kenneth Marshall" Subject: Re: PG optimization question From: =?utf-8?Q?Pierre_Fr=C3=A9d=C3=A9ric_Caillau?= =?utf-8?Q?d?= Cc: pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <4B485975.70506@zhukcity.ru> <2f4958ff1001090418i78dee992t5ff2d78a54187c07@mail.gmail.com> <4B4879A0.2060703@zhukcity.ru> <20100109124646.GA8123@it.is.rice.edu> <4B487D9C.9020507@zhukcity.ru> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <4B487D9C.9020507@zhukcity.ru> User-Agent: Opera Mail/9.62 (Linux) X-Ovh-Tracer-Id: 11715832956565456573 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=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/167 X-Sequence-Number: 37047 > That may help with the queries speed (not a problem now), but we'll then > have to add UNION statement for daily staging table for other 5% of > requests, right? And there would be a moment when daily message is in > archive table AND in daily table (while transferring from daily table to > archive). > Our main problem is in blocking when doing DELETE (app sometimes freezes > for a long time), and also we have to do VACUUM on live table, which is > not acceptable in our app. > > Thanks for your reply, I was kinda worried about number of partitions > and how this would affect PG query execution speed. > > Kenneth Marshall wrote: >>> Oh, btw, 95% of queries are searching rows for current date (last 24 >>> hours). >>> >> >> You may want to use a daily staging table and then flush to the monthly >> archive tables at the end of the day. If the rows in the archive tables are never updated, this strategy means you never need to vacuum the big archive tables (and indexes), which is good. Also you can insert the rows into the archive table in the order of your choice, the timestamp for example, which makes it nicely clustered, without needing to ever run CLUSTER. And with partitioning you can have lots of indexes on the staging table (and current months partition) (to speed up your most common queries which are likely to be more OLTP), while using less indexes on the older partitions (saves disk space) if queries on old partitions are likely to be reporting queries which are going to grind through a large part of the table anyway.