Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 62D599FBBE9 for ; Tue, 8 May 2007 07:09:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 59459-05-2 for ; Tue, 8 May 2007 07:09:31 -0300 (ADT) X-Greylist: whitelisted by SQLgrey-1.7.4 Received: from smtp8-g19.free.fr (smtp8-g19.free.fr [212.27.42.65]) by postgresql.org (Postfix) with ESMTP id 3D3779FBBD2 for ; Tue, 8 May 2007 07:09:31 -0300 (ADT) Received: from pulsar.staff.proxad.net (pulsar.staff.proxad.net [213.228.1.109]) by smtp8-g19.free.fr (Postfix) with ESMTP id 21BF3199DE; Tue, 8 May 2007 12:09:30 +0200 (CEST) Date: Tue, 8 May 2007 12:09:30 +0200 (CEST) From: Pomarede Nicolas X-X-Sender: npomarede@localhost To: ismo.tuononen@solenovo.fi cc: pgsql-performance@postgresql.org Subject: Re: truncate a table instead of vaccum full when count(*) is 0 In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/97 X-Sequence-Number: 24487 On Tue, 8 May 2007, ismo.tuononen@solenovo.fi wrote: > > > On Tue, 8 May 2007, Pomarede Nicolas wrote: > >> As you can see, with hundreds of thousands events a day, this table will need >> being vaccumed regularly to avoid taking too much space (data and index). >> >> Note that processing rows is quite fast in fact, so at any time a count(*) on >> this table rarely exceeds 10-20 rows. >> >> For the indexes, a good way to bring them to a size corresponding to the >> actual count(*) is to run 'reindex'. > > why you have index in table where is only 10-20 rows? > > are those indexes to prevent some duplicate rows? I need these indexes to sort rows to process in chronological order. I'm also using an index on 'oid' to delete a row after it was processed (I could use a unique sequence too, but I think it would be the same). Also, I sometime have peaks that insert lots of data in a short time, so an index on the event's date is useful. And as the number of effective row compared to the number of dead rows is only 1%, doing a count(*) for example takes many seconds, even if the result of count(*) is 10 row (because pg will sequential scan all the data pages of the table). Without index on the date, I would need sequential scan to fetch row to process, and this would be slower due to the high number of dead rows. > > I have some tables just to store unprosessed data, and because there is > only few rows and I always process all rows there is no need for > indexes. there is just column named id, and when I insert row I take > nextval('id_seq') : > > insert into some_tmp_table(id,'message',...) values (nextval('id_seq'),'do > something',...); > > I know that deleting is slower than with indexes, but it's still fast > enough, because all rows are in memory. > > and that id-column is just for delete, it's unique and i can always delete > using only it. > > Ismo Nicolas