X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2D3F83A4573 for ; Thu, 6 Jan 2005 17:07:34 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17955-07 for ; Thu, 6 Jan 2005 17:07:06 +0000 (GMT) Received: from davinci.ethosmedia.com (server226.ethosmedia.com [209.128.84.226]) by svr1.postgresql.org (Postfix) with ESMTP id 375113A4590 for ; Thu, 6 Jan 2005 17:07:05 +0000 (GMT) Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 6873317 for pgsql-performance@postgresql.org; Thu, 06 Jan 2005 09:08:42 -0800 From: Josh Berkus Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: Low Performance for big hospital server .. Date: Thu, 6 Jan 2005 09:06:55 -0800 User-Agent: KMail/1.6.2 References: <1104831107.41da6283add0c@webmail.moph.go.th> <1104939342.41dc094ecb1cf@webmail.moph.go.th> <758d5e7f050106041510f07dc5@mail.gmail.com> In-Reply-To: <758d5e7f050106041510f07dc5@mail.gmail.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200501060906.55832.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/68 X-Sequence-Number: 9758 Dawid, > Ahh, the huge update. Below are my "hints" I've > found while trying to optimize such updates. > Divide the update, if possible. This way query uses > less memory and you may call VACUUM inbetween > updates. To do this, first SELECT INTO TEMPORARY > table the list of rows to update (their ids or something), > and then loop through it to update the values. There are other ways to deal as well -- one by normalizing the database. Often, I find that massive updates like this are caused by a denormalized database. For example, Lyris stores its "mailing numbers" only as repeated numbers in the recipients table. When a mailing is complete, Lyris updates all of the recipients .... up to 750,000 rows in the case of my client ... to indicate the completion of the mailing (it's actually a little more complicated than that, but the essential problem is the example) It would be far better for Lyris to use a seperate mailings table, with a status in that table ... which would then require only *one* update row to indicate completion, instead of 750,000. I can't tell you how many times I've seen this sort of thing. And the developers always tell me "Well, we denormalized for performance reasons ... " -- Josh Berkus Aglio Database Solutions San Francisco