Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A1A209FC349 for ; Fri, 18 May 2007 19:39:19 -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 51191-06 for ; Fri, 18 May 2007 19:39:10 -0300 (ADT) X-Greylist: delayed 00:06:40.313698 by SQLgrey-1.7.4 Received: from mail.emolecules.com (66-226-76-106.dedicated.abac.net [66.226.76.106]) by postgresql.org (Postfix) with ESMTP id 62B9C9FC290 for ; Fri, 18 May 2007 19:39:14 -0300 (ADT) Received: (qmail 7128 invoked by uid 2020); 18 May 2007 15:32:32 -0700 Received: from wsip-68-224-174-233.sd.sd.cox.net (HELO ?192.168.0.3?) (68.224.174.233) by 192.168.0.4 with SMTP; 18 May 2007 15:32:32 -0700 Message-ID: <464E29A4.4050309@emolecules.com> Date: Fri, 18 May 2007 15:33:08 -0700 From: Craig James User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 To: cyber-postgres@midnightfantasy.com CC: pgsql-performance@postgresql.org Subject: Re: 121+ million record table perf problems References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/355 X-Sequence-Number: 24745 > > I've got a table with ~121 million records in it. Select count on it > currently takes ~45 minutes, and an update to the table to set a value > on one of the columns I finally killed after it ran 17 hours and had > still not completed. Queries into the table are butt slow, and > > The update query that started this all I had to kill after 17hours. > It should have updated all 121+ million records. That brought my > select count down to 19 minutes, but still a far cry from acceptable. If you have a column that needs to be updated often for all rows, separate it into a different table, and create a view that joins it back to the main table so that your application still sees the old schema. This will greatly speed your update since (in Postgres) and update is the same as a delete+insert. By updating that one column, you're re-writing your entire 121 million rows. If you separate it, you're only rewriting that one column. Don't forget to vacuum/analyze and reindex when you're done. Better yet, if you can stand a short down time, you can drop indexes on that column, truncate, then do 121 million inserts, and finally reindex. That will be MUCH faster. Craig