Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 81A029FB34D for ; Sun, 14 Jan 2007 03:35:31 -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 47220-02 for ; Sun, 14 Jan 2007 03:35:22 -0400 (AST) X-Greylist: delayed 01:00:00.02459 by SQLgrey-1.7.4 Received: from pd5mo2so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net [24.71.223.10]) by postgresql.org (Postfix) with ESMTP id 23A0A9FB348 for ; Sun, 14 Jan 2007 03:35:23 -0400 (AST) Received: from pd4mr1so.prod.shaw.ca (pd4mr1so-qfe3.prod.shaw.ca [10.0.141.212]) by l-daemon (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0JBU000LDI79DG00@l-daemon> for pgsql-sql@postgresql.org; Sat, 13 Jan 2007 23:33:09 -0700 (MST) Received: from pn2ml2so.prod.shaw.ca ([10.0.121.146]) by pd4mr1so.prod.shaw.ca (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) with ESMTP id <0JBU009YVI797PH0@pd4mr1so.prod.shaw.ca> for pgsql-sql@postgresql.org; Sat, 13 Jan 2007 23:33:09 -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 <0JBU00AEAI79IJ71@l-daemon> for pgsql-sql@postgresql.org; Sat, 13 Jan 2007 23:33:09 -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 l0E6XB78011540 for ; Sat, 13 Jan 2007 22:33:11 -0800 Date: Sat, 13 Jan 2007 22:33:07 -0800 From: Ken Subject: update query taking 24+ hours To: pgsql-sql@postgresql.org Message-id: <45A9CEA3.3020903@kwasnicki.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit User-Agent: Thunderbird 1.5.0.8 (X11/20061025) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/43 X-Sequence-Number: 27195 Hello, 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. I have two tables: Master: x int4 y int4 val1 int2 val2 int2 Import: x int4 y int4 val int2 Each table has about 100 million rows. I want to populate val2 in Master with val from Import where the two tables match on x and y. So, my query looks like: UPDATE Master SET val2=Import.val WHERE Master.x=Import.x AND Master.y=Import.y; Both tables have indexes on the x and y columns. Will that help? Is there a better way to do this? In each table x,y are unique, does that make a difference? ie: would it be faster to run some kind of query, or loop, that just goes through each row in Import and updates Master (val2=val) where x=x and y=y? If this approach would be better how to construct such a SQL statement? The other weird thing is that when I monitor the system with xload it shows two bars of load, and the hard drive is going nuts, so far my database directory has grown by 25GB, however when I run "top" the system shows 98% idle and the postmaster process is usually only between 1-2% CPU, although it is using 50% (750MB) ram. Also the process shows up with a "D" status in the "S" column. Not sure what is going on. If the size of the tables makes what I'm trying to do insane, or if I just have a bad SQL approach, or if something is wrong with my postgres configuration. Really appreciate any help! Thanks! Ken