pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Julien Rouhaud <julien.rouhaud@dalibo.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: sudalai <sudalait2@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: Index file got removed
Date: Thu, 17 Nov 2016 22:31:59 +0100
Message-ID: <e7f50e1e-afa2-a31a-7c40-a57e4c501485@dalibo.com> (raw)
In-Reply-To: <23523.1479317197@sss.pgh.pa.us>
References: <1479294998857-5930602.post@n3.nabble.com>
	<CAB7nPqRubsq9d1_ox=rkxLC-23QQ-1T3OUsiZ6O3B+RwqqqBRw@mail.gmail.com>
	<23523.1479317197@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 16/11/2016 18:26, Tom Lane wrote:
> Michael Paquier <michael.paquier@gmail.com> writes:
>> On Wed, Nov 16, 2016 at 3:16 AM, sudalai <sudalait2@gmail.com> 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

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

fix_at_addindex.diff (text/x-diff, 836B) download diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.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 = !is_rebuild; /* skip index build if phase 3 will do it or we're reusing an old one */ skip_build = tab->rewrite > 0 || OidIsValid(stmt->oldNode); + /* keep track of original tablespace if we're reusing old index */ + if (tab->rewrite == 0 && OidIsValid(stmt->oldNode)) + { + Oid tablespaceid = get_rel_tablespace(stmt->oldNode); + + if (tablespaceid == InvalidOid) + tablespaceid = MyDatabaseTableSpace; + + stmt->tableSpace = get_tablespace_name(tablespaceid); + } /* suppress notices when rebuilding existing index */ quiet = is_rebuild;

view thread (15+ messages)  latest in thread

Message-ID: <e7f50e1e-afa2-a31a-7c40-a57e4c501485@dalibo.com>
Permalink:  ../e7f50e1e-afa2-a31a-7c40-a57e4c501485@dalibo.com/
Also on:    postgresql.org/message-id/e7f50e1e-afa2-a31a-7c40-a57e4c501485@dalibo.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: julien.rouhaud@dalibo.com, tgl@sss.pgh.pa.us, michael.paquier@gmail.com, sudalait2@gmail.com
  Subject: Re: Index file got removed
  In-Reply-To: <e7f50e1e-afa2-a31a-7c40-a57e4c501485@dalibo.com>
  References: <1479294998857-5930602.post@n3.nabble.com> <CAB7nPqRubsq9d1_ox=rkxLC-23QQ-1T3OUsiZ6O3B+RwqqqBRw@mail.gmail.com> <23523.1479317197@sss.pgh.pa.us> <e7f50e1e-afa2-a31a-7c40-a57e4c501485@dalibo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox