Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 52CFF9FB228 for ; Mon, 15 Jan 2007 00:48:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 64195-02 for ; Mon, 15 Jan 2007 00:47:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from pd3mo2so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net [24.71.223.10]) by postgresql.org (Postfix) with ESMTP id 22E069FB320 for ; Mon, 15 Jan 2007 00:47:54 -0400 (AST) Received: from pd2mr5so.prod.shaw.ca (pd2mr5so-qfe3.prod.shaw.ca [10.0.141.8]) by l-daemon (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0JBW00AGM7ZUYW50@l-daemon> for pgsql-sql@postgresql.org; Sun, 14 Jan 2007 21:47:54 -0700 (MST) Received: from pn2ml9so.prod.shaw.ca ([10.0.121.7]) by pd2mr5so.prod.shaw.ca (Sun Java System Messaging Server 6.2-2.05 (built Apr 28 2005)) with ESMTP id <0JBW00EV97ZTXSG1@pd2mr5so.prod.shaw.ca> for pgsql-sql@postgresql.org; Sun, 14 Jan 2007 21:47:54 -0700 (MST) Received: from smokehouse.2829.stephens ([24.84.33.151]) by l-daemon (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0JBW009AZ7ZPXN00@l-daemon> for pgsql-sql@postgresql.org; Sun, 14 Jan 2007 21:47:49 -0700 (MST) Received: from [172.16.234.10] ([172.16.234.10]) by smokehouse.2829.stephens (8.13.4/8.12.8) with ESMTP id l0F4lpgO020112; Sun, 14 Jan 2007 20:47:51 -0800 Date: Sun, 14 Jan 2007 20:47:46 -0800 From: Ken Subject: Re: update query taking 24+ hours In-reply-to: <12574.1168803032@sss.pgh.pa.us> To: pgsql-sql@postgresql.org Cc: Tom Lane Message-id: <45AB0772.3010109@kwasnicki.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit References: <45A9CEA3.3020903@kwasnicki.com> <12574.1168803032@sss.pgh.pa.us> User-Agent: Thunderbird 1.5.0.8 (X11/20061025) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/45 X-Sequence-Number: 27197 Thanks Tom! explain output: Merge Join (cost=60454519.54..70701005.93 rows=682951183 width=22) Merge Cond: (("outer".y = "inner".y) AND ("outer".x = "inner".x)) -> Sort (cost=41812068.08..42304601.78 rows=197013479 width=20) Sort Key: Master.y, Master.x -> Seq Scan on Master (cost=0.00..3129037.79 rows=197013479 width=20) -> Sort (cost=18642451.46..18879400.92 rows=94779784 width=10) Sort Key: Import.y, Import.x -> Seq Scan on Import (cost=0.00..1460121.84 rows=94779784 width=10) Don't really understand all those numbers but they look big, to me. work_mem is set to 262144. should it be bigger? i have 1.5GB ram on the system. also i set /proc/sys/kernel/shmmax to 256000000. too big, too small? There are no foreign key constraints on either table. I don't know what hashjoin or sort-and-mergejoin are but I will look into them. Thanks! Ken Tom Lane wrote: > Ken writes: > >> I have postgres 8.1 on a linux box: 2.6Ghz P4, 1.5GB ram, 320GB hard >> drive. I'm performing an update between two large tables and so far >> it's been running for 24+ hours. >> UPDATE Master SET val2=Import.val WHERE Master.x=Import.x AND >> Master.y=Import.y; >> > > What does EXPLAIN say about that? (Don't try EXPLAIN ANALYZE, > but a plain EXPLAIN should be quick enough.) > > >> Both tables have indexes on the x and y columns. Will that help? >> > > A two-column index would have helped a lot more, probably, although > with so many rows to process I'm not sure that indexes are useful > anyway. For really bulk updates a hashjoin or sort-and-mergejoin > plan is probably the best bet. > > BTW, both of those would require plenty of work_mem to run fast > ... what have you got work_mem set to? > > And possibly even more to the point, do you have any foreign key > constraints leading into or out of the Master table? > > regards, tom lane > >