X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 0DF4A9F9CEE for ; Tue, 16 May 2006 23:31:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 76213-10 for ; Tue, 16 May 2006 23:31:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 52A1F9F9C18 for ; Tue, 16 May 2006 23:31:38 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k4H2VVuP004441 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 16 May 2006 20:31:34 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.6/8.13.6) with ESMTP id k4H2VVHq060897; Tue, 16 May 2006 20:31:31 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.6/8.13.6/Submit) id k4H2VVTk060896; Tue, 16 May 2006 20:31:31 -0600 (MDT) (envelope-from mfuhr) Date: Tue, 16 May 2006 20:31:30 -0600 From: Michael Fuhr To: Jonathan Blitz Cc: pgsql-performance@postgresql.org Subject: Re: Adding and filling new column on big table Message-ID: <20060517023130.GA60671@winnie.fuhr.org> References: <01b401c6794f$f27355e0$ddf71005@jonathanlaptop> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <01b401c6794f$f27355e0$ddf71005@jonathanlaptop> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/356 X-Sequence-Number: 19143 On Wed, May 17, 2006 at 03:19:26AM +0200, Jonathan Blitz wrote: > I have a table of about 500,000 rows. > > I need to add a new column and populate it. > > So, I have tried to run the following command. The command never finishes (I > gave up after about and hour and a half!). If you install contrib/pgstattuple you can figure out how fast the update is running. Run "SELECT * FROM pgstattuple('mytable')" a few times and note the rate at which dead_tuple_count is increasing. If it's not increasing at all then query pg_locks and look for locks where "granted" is false. I created a test table, populated it with 500,000 rows of random data, and ran the update you posted. On a 500MHz Pentium III with 512M RAM and a SCSI drive from the mid-to-late 90s, running PostgreSQL 8.1.3 on FreeBSD 6.1, the update finished in just over two minutes. The table had one index (the primary key). > Note that none of the columns have indexes. Do you mean that no columns in the table have indexes? Or that the columns referenced in the update don't have indexes but that other columns do? What does "\d mytable" show? Do other tables have foreign key references to this table? What non-default settings do you have in postgresql.conf? What version of PostgreSQL are you running and on what platform? How busy is the system? What's the output of "EXPLAIN UPDATE mytable ..."? -- Michael Fuhr