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 1kAbag-0004GU-Jd for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Aug 2020 16:14:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kAbaf-0000BR-5c for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Aug 2020 16:14:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kAbae-0000BK-VO for pgsql-bugs@lists.postgresql.org; Tue, 25 Aug 2020 16:14:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kAbac-0004WZ-JF for pgsql-bugs@postgresql.org; Tue, 25 Aug 2020 16:14:28 +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 07PGEKaQ2745155; Tue, 25 Aug 2020 12:14:20 -0400 From: Tom Lane To: Bruce Momjian cc: Michael Paquier , Robins Tharakan , pgsql-bugs@postgresql.org Subject: Re: ALTER TABLE ALTER COLUMN SET TYPE crash In-reply-to: <20200825155544.GG32540@momjian.us> References: <20200825060511.GF2017@paquier.xyz> <20200825155544.GG32540@momjian.us> Comments: In-reply-to Bruce Momjian message dated "Tue, 25 Aug 2020 11:55:44 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2745153.1598372060.1@sss.pgh.pa.us> Date: Tue, 25 Aug 2020 12:14:20 -0400 Message-ID: <2745154.1598372060@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bruce Momjian writes: > On Tue, Aug 25, 2020 at 03:05:11PM +0900, Michael Paquier wrote: >> On Tue, Aug 25, 2020 at 02:14:06PM +1000, Robins Tharakan wrote: >>> Unlike a recently reported similar issue, executing the following ALTER >>> TABLE on the regression database crashes Postgres (master). >> Such reports are constructive! I can reproduce the crash here down to >> 9.5. From what I can see, the problem comes from ATRewriteTable() -> >> ExecEvalExpr() when we evaluate expressions with inputs coming from >> the old tuple. It looks like a memory corruption issue or a context >> issue at quick glance, and I cannot get a clean backtrace. I think the nature of the problem (and Robins' other report too) is pretty clear. We have a SQL or plpgsql function that's trying to access a table that is inconsistent during an ALTER TABLE operation. The function would be locked out from seeing that transient state if it were in another session, thanks to normal locking rules; but the lock acquisition rules don't prevent same-session accesses. ALTER TABLE and related utility commands contain guards against the reverse form of this problem: CheckTableNotInUse will bitch if there's some already-active outer query referencing the table. But we haven't thought about the possibility of one of these commands executing user-defined code midway through. regards, tom lane