Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3hH1-0003WN-6j for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2020 14:21:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3hGz-0008Pl-K4 for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2020 14:21:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3hGz-0008Om-6U for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2020 14:21:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j3hGs-0006NE-OJ for pgsql-general@postgresql.org; Mon, 17 Feb 2020 14:21:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 01HELCoa000574; Mon, 17 Feb 2020 09:21:12 -0500 From: Tom Lane To: Jeremy Finzel cc: Postgres General Subject: Re: Cases where alter table set type varchar(longer length) still needs table rewrite In-reply-to: References: Comments: In-reply-to Jeremy Finzel message dated "Mon, 17 Feb 2020 08:04:53 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <572.1581949272.1@sss.pgh.pa.us> Date: Mon, 17 Feb 2020 09:21:12 -0500 Message-ID: <573.1581949272@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jeremy Finzel writes: > I have a table foo with 100 million rows, and a column: > - id character varying(20) > The following command is the one that we expect to execute very quickly (we > are not seeing any locking), but it is instead taking a very long time: > - ALTER TABLE foo ALTER COLUMN id TYPE varchar(100); Hm, the code is supposed to avoid a table rewrite, but I wonder if there's something else that's not being avoided, such as an index rebuild or foreign-key verification. Could we see the whole table definition, eg from psql \d+ ? regards, tom lane