Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id CB87CB5DC5D for ; Thu, 8 Sep 2011 11:10:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 83874-01-3 for ; Thu, 8 Sep 2011 14:10:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from elizabeth.gransy.com (ns2.gransy.com [89.187.132.100]) by mail.postgresql.org (Postfix) with ESMTP id F3BD7B5DBE0 for ; Thu, 8 Sep 2011 11:10:21 -0300 (ADT) Received: from sq.gransy.com (localhost [127.0.0.1]) by elizabeth.gransy.com (Postfix) with ESMTP id 8BF2C15E4124; Thu, 8 Sep 2011 16:10:19 +0200 (CEST) Received: from 78.45.133.255 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Thu, 8 Sep 2011 16:10:19 +0200 Message-ID: In-Reply-To: <004301cc6e26$015a75e0$040f61a0$@devshock.com> References: <004301cc6e26$015a75e0$040f61a0$@devshock.com> Date: Thu, 8 Sep 2011 16:10:19 +0200 Subject: Re: how delete/insert/update affects select performace? From: "Tomas Vondra" To: "Anibal David Acosta" Cc: pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.585 tagged_above=-10 required=5 tests=BAYES_00=-1.9, SARE_MILLIONSOF=0.315 X-Spam-Level: X-Archive-Number: 201109/76 X-Sequence-Number: 44852 On 8 Září 2011, 14:51, Anibal David Acosta wrote: > Hi! > > > > I have a table not too big but with aprox. 5 millions of rows, this table > must have 300 to 400 select per second. But also must have 10~20 > delete/insert/update per second. > > So, I need to know if the insert/delete/update really affect the select > performance and how to deal with it. Yes, insert/update do affect query performance, because whenever a row is modified a new copy is created. So the table might grow over time, and bigger tables mean more data to read. There are two ways to prevent this: 1) autovacuum - has to be configured properly (watch the table size and number of rows, and if it grows then make it a bit more aggressive) 2) HOT > The table structure is very simple: > > account_id integer (PK) > > service_id integer (PK) > > enabled char(1) > > The index created on this has the same 3 columns. > > Most of time the table has more insert or delete than update, when update > occur the column changed is enabled; So there's one index on all three columns? I'd remove the "enabled" from the index, it's not going to help much I guess and it makes HOT possible (the modified column must not be indexed). Plus there will be one less index (the other two columns are already a PK, so there's a unique index). Tomas