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 1iIQtT-0005Ro-MX for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Oct 2019 05:21:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iIQtS-0001fa-Fk for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Oct 2019 05:21:42 +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 1iIQtR-0001fN-CW for pgsql-bugs@lists.postgresql.org; Thu, 10 Oct 2019 05:21:42 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iIQtO-0004cb-4t for pgsql-bugs@lists.postgresql.org; Thu, 10 Oct 2019 05:21:40 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 4CC1D6CF; Thu, 10 Oct 2019 01:21:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 10 Oct 2019 01:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=1s6lQTOCxWMdB892kRf41niQn7B MtBXxk7LB/xnANLw=; b=ewz/Ewf1+b0AH2cC0o99GL5V4g4XQ5lAd/gRfpXahJ6 n+1XgCqh6QBraBI+6FmJoMVYUjNwrPBEp3uSOPfyXujNNsM62EHwTz/CsbR+KfbL Mv6CX4u+PiK1WGwhETH8u5MjSQQKOUxUfYiuXytg1gRDpDWtgsz2HtuSnOEA51Mz BUDjF3jabtirU9cEUyOWNFXTlOF9eOVxvJY7g4aHiaZFGsqEI6jt1gWlrSwTnLjJ Aj2VxXsZnZLeBmPuVulXYQSf30IMl7NyCJuOgbDtN11iEGiyKGSDPdgwaHuiFplf xU0aP8lW9BMhZfHxOhM7AWz8PyRScTbnxEEuggzh2iQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=1s6lQT OCxWMdB892kRf41niQn7BMtBXxk7LB/xnANLw=; b=AN/F/zggil2SE0AbfHWKih pb0FaWNO9Ey+lv6LQP4qZ+llXkvsSkwNYCLtg/Ab4OyBPqPdOM4ACw8kWQ6M4JhD iIpz+FwS5sZ+2leCYJURE0eBb6o2IF8CevOmaSl2tVn8Cl+BAV8S3GcGq9cZLSdX pj9GV7vBfC5cNXs30vb1UYDiyDUzI4eu7uTQm3e+DoqL1FdB0+/twPviOrmAoSPZ 5MtslFLrHvJukzRbs9yDOjAFvAiiEidBqjj9MrXW6ex5ufPsyZwNfIHXuo1l297s hv6MkflwnyU98nHG/P4aPllffN45iF9XfC6lCmG/k+GZGatq67p2tklUu2x1tRoQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedriedvgdeliecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuffhomhgrih hnpehtrggslhgvtghmughsrdgtfienucfkphepieejrdduiedtrddvudekrddvfeejnecu rfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvgenuc evlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-218-237.hsd1.ca.comcast.net [67.160.218.237]) by mail.messagingengine.com (Postfix) with ESMTPA id 86593D60062; Thu, 10 Oct 2019 01:21:35 -0400 (EDT) Date: Wed, 9 Oct 2019 22:21:33 -0700 From: Andres Freund To: Alvaro Herrera Cc: deathlock13@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16038: Alter table - SegFault Message-ID: <20191010052133.eqfw5euzbrtf5nwu@alap3.anarazel.de> References: <16038-5c974541f2bf6749@postgresql.org> <20191004144352.GA15934@alvherre.pgsql> <20191004152624.6hcdsyqgp6qntw2h@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191004152624.6hcdsyqgp6qntw2h@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2019-10-04 08:26:24 -0700, Andres Freund wrote: > On 2019-10-04 11:43:52 -0300, Alvaro Herrera wrote: > > On 2019-Oct-04, PG Bug reporting form wrote: > > > > > alter table test.testa > > > add column idb numeric(10,0) NOT NULL DEFAULT nextval('test.sq_testb'), > > > add column fk_tmpb varchar(20); > > > > > > server process (PID 21884) was terminated by signal 11: Segmentation fault > > > - empty table - alter goes ok , split alter into 2 add col - works too Thanks for the bug report! I've pushed a fix, which will be included in the next minor release. If you need a workaround until then, you can avoid the crash by only adding one column add a time. > > Hmm, confirmed, here's the stack trace: > > The trailing attributes in the new slot in AtRewriteTable() aren't > necessarily set to isnull=true. So to trigger the problem, one needs a > rewrite triggered by *another* column (otherwise we'll not hit this > path), combined with a new column that doesn't have a default value. I > think that's probably my bug. > > This seems to fix the problem: > > diff --git i/src/backend/commands/tablecmds.c w/src/backend/commands/tablecmds.c > index 05593f33162..6f72b08a87d 100644 > --- i/src/backend/commands/tablecmds.c > +++ w/src/backend/commands/tablecmds.c > @@ -4890,6 +4890,14 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) > table_slot_callbacks(oldrel)); > newslot = MakeSingleTupleTableSlot(newTupDesc, > table_slot_callbacks(newrel)); > + > + /* > + * Set all columns in the new slot to NULL initially, to ensure > + * columns added as part of the rewrite are initialized to > + * NULL. That's necessary as tab->newvals will not contain an > + * expression for columns with a NULL default. > + */ > + ExecStoreAllNullTuple(newslot); > } Pushed, after adding some tests. Greetings, Andres Freund