Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBR0B-00059f-9c for pgsql-performance@postgresql.org; Tue, 11 Sep 2012 13:59:43 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBR09-0000Ko-LL for pgsql-performance@postgresql.org; Tue, 11 Sep 2012 13:59:42 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by depesz.com with esmtpa (Exim 4.80) (envelope-from ) id 1TBR08-0001GS-5r; Tue, 11 Sep 2012 15:59:40 +0200 Date: Tue, 11 Sep 2012 15:59:40 +0200 From: hubert depesz lubaczewski To: AI Rumman Cc: pgsql-performance@postgresql.org Subject: Re: add column with default value is very slow Message-ID: <20120911135939.GA1656@depesz.com> Reply-To: depesz@depesz.com References: <20120911134425.GA27828@depesz.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -2.2 (--) X-Archive-Number: 201209/41 X-Sequence-Number: 47787 On Tue, Sep 11, 2012 at 07:55:24PM +0600, AI Rumman wrote: > I added the excel file for locks data. well, it worked, but why didn't you just make it text file, in notepad or something like this? > I was surprised to see that while I was updating a single column value for > all records in a tables, all indexes are locked by the server. alter table is not locked (At least looking at the pg_locks data you showed). this means - it just takes long time. Please do: select pg_total_relation_size('entity'); to see how much data it has to rewrite. for future - just don't do alter table, with default, and not null. doing it via add column; set default; batch-backfill data, set not null will take longer but will be done with much shorter locks. Best regards, depesz -- The best thing about modern society is how easy it is to avoid contact with it. http://depesz.com/