Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oH5PR-0003qi-4m for pgsql-admin@arkaria.postgresql.org; Thu, 28 Jul 2022 15:26:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oH5PP-0007yo-Jf for pgsql-admin@arkaria.postgresql.org; Thu, 28 Jul 2022 15:26:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oH5PP-0007yf-99 for pgsql-admin@lists.postgresql.org; Thu, 28 Jul 2022 15:26:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oH5PM-00054s-UI for pgsql-admin@lists.postgresql.org; Thu, 28 Jul 2022 15:26:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 26SFQdOm3421792; Thu, 28 Jul 2022 11:26:39 -0400 From: Tom Lane To: "David G. Johnston" cc: Ron , pgsql-admin Subject: Re: What to watch out for when ALTERing NUMERIC(38,0) to BIGINT? In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Thu, 28 Jul 2022 08:19:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3421790.1659021999.1@sss.pgh.pa.us> Date: Thu, 28 Jul 2022 11:26:39 -0400 Message-ID: <3421791.1659021999@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Thu, Jul 28, 2022 at 8:13 AM Ron wrote: >> Besides what's mentioned in >> https://www.postgresql.org/docs/12/ddl-alter.html#id-1.5.4.8.10, what >> happens *internally* when I run: >> ALTER TABLE foo ALTER COLUMN bar TYPE BIGINT; > IIUC, that would be the silver lining in all of this - the rewritten table > would have zero fragmentation and bloat. Yeah. What happens internally is a table rewrite: the entire content of the table (and its indexes) is written into a new set of files. At commit, the old files are deleted. The main gotchas, for a large table, are the transient disk space consumption and the fact that the table stays exclusively locked the whole time. regards, tom lane