Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c7UI3-0002c5-3n for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Nov 2016 21:32:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c7UI2-0005w4-8S for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Nov 2016 21:32:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c7UI1-0005vW-9x for pgsql-bugs@postgresql.org; Thu, 17 Nov 2016 21:32:13 +0000 Received: from mimolette.dalibo.net ([212.85.157.144] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c7UHt-0002tl-NO for pgsql-bugs@postgresql.org; Thu, 17 Nov 2016 21:32:12 +0000 Received: from nol.local (aur75-1-78-192-238-147.fbxo.proxad.net [78.192.238.147]) by mail.dalibo.com (Postfix) with ESMTPSA id 9ED6D2C06A1; Thu, 17 Nov 2016 22:32:03 +0100 (CET) Subject: Re: Index file got removed To: Tom Lane , Michael Paquier References: <1479294998857-5930602.post@n3.nabble.com> <23523.1479317197@sss.pgh.pa.us> Cc: sudalai , PostgreSQL mailing lists From: Julien Rouhaud Message-ID: Date: Thu, 17 Nov 2016 22:31:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <23523.1479317197@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------AFEE1C1241FB3606F495E422" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------AFEE1C1241FB3606F495E422 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 16/11/2016 18:26, Tom Lane wrote: > Michael Paquier writes: >> On Wed, Nov 16, 2016 at 3:16 AM, sudalai wrote: >>> I am creating a table test and index for that table on default tablespace. >>> Then i'm changing default_tablespace to some other tablespace. >>> After that altering one of the index column. >>> This alter operation moves the index to new default_tablespace, but index >>> file is missing in new tablespace. > >> I am just digging into it, instinctively that would be something in >> tablecmds.c.. > > I'm betting that where it reconstructs textual commands to create the new > indexes, it's forgotten to do anything about tablespaces. I looked at it, and IIUC the issue is that during AT_PASS_OLD_INDEX pass, ATExecAddIndex defines a new index using the old heap in original tablespace (stmt->oldNode is valid), and DefineIndex will create a new cat entry using the current default tablespace instead of the existing index one. The only way I found to fix this is to save the original tablespace in ATExecAddIndex() if the old heap is reused, see attached patch. I'm not at all familiar with this part of code, but at least initdb and regression tests don't fail. -- Julien Rouhaud http://dalibo.com - http://dalibo.org --------------AFEE1C1241FB3606F495E422 Content-Type: text/x-diff; name="fix_at_addindex.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fix_at_addindex.diff" diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablec= mds.c index f97bee5..6ab7556 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -5914,6 +5914,16 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel, check_rights =3D !is_rebuild; /* skip index build if phase 3 will do it or we're reusing an old one */ skip_build =3D tab->rewrite > 0 || OidIsValid(stmt->oldNode); + /* keep track of original tablespace if we're reusing old index */ + if (tab->rewrite =3D=3D 0 && OidIsValid(stmt->oldNode)) + { + Oid tablespaceid =3D get_rel_tablespace(stmt->oldNode); + + if (tablespaceid =3D=3D InvalidOid) + tablespaceid =3D MyDatabaseTableSpace; + + stmt->tableSpace =3D get_tablespace_name(tablespaceid); + } /* suppress notices when rebuilding existing index */ quiet =3D is_rebuild; =20 --------------AFEE1C1241FB3606F495E422 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------AFEE1C1241FB3606F495E422--