Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 323BB9FB308 for ; Tue, 10 Apr 2007 13:08:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 88190-09 for ; Tue, 10 Apr 2007 13:08:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4F2DB9FB509 for ; Tue, 10 Apr 2007 13:08:16 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l3AG8EGo026926; Tue, 10 Apr 2007 12:08:14 -0400 (EDT) To: Drew Wilson cc: pgsql-performance@postgresql.org Subject: Re: how to efficiently update tuple in many-to-many relationship? In-reply-to: References: <233A9987-ABA5-4491-A304-FDA1F8FCD962@gmail.com> <14019.1176155022@sss.pgh.pa.us> <22512E5C-A60F-43E7-A370-257F7AF956FD@gmail.com> <16374.1176171185@sss.pgh.pa.us> <25200.1176213242@sss.pgh.pa.us> Comments: In-reply-to Drew Wilson message dated "Tue, 10 Apr 2007 08:37:31 -0700" Date: Tue, 10 Apr 2007 12:08:14 -0400 Message-ID: <26925.1176221294@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/231 X-Sequence-Number: 24108 Drew Wilson writes: > If I understand the EXPLAIN ANALYZE results below, it looks like the > time spent applying the "set is_public = true" is much much more than > the fetch. I don't see any triggers firing. Nope, there aren't any. 8.2 is smart enough to bypass firing FK triggers on UPDATE if the key columns didn't change. Of course that check takes a certain amount of time, but I don't think it's a large amount. So basically we're looking at index update and WAL logging as the major costs here, I think. [ thinks for a bit... ] Part of the problem might be that the working set for updating all the indexes is too large. What do you have shared_buffers set to, and can you increase it? Oh, and checkpoint_segments at 8 is probably still not nearly enough; if you have disk space to spare, try something like 30 (which'd eat about 1Gb of disk space). It might be educational to set checkpoint_warning to 300 or so and watch the log to see how often checkpoints happen during the update --- you want them at least a couple minutes apart even during max load. Also, bumping up wal_buffers a little might help some, for large updates like this. I've heard people claim that values as high as 64 are helpful. regards, tom lane