pgsql: Make sure ALTER TABLE preserves index tablespaces.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make sure ALTER TABLE preserves index tablespaces.
Date: 2016-11-23 18:46:18
Message-ID: E1c9cYk-0000tZ-Ns@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make sure ALTER TABLE preserves index tablespaces.

When rebuilding an existing index, ALTER TABLE correctly kept the
physical file in the same tablespace, but it messed up the pg_class
entry if the index had been in the database's default tablespace
and "default_tablespace" was set to some non-default tablespace.
This led to an inaccessible index.

Fix by fixing pg_get_indexdef_string() to always include a tablespace
clause, whether or not the index is in the default tablespace. The
previous behavior was installed in commit 537e92e41, and I think it just
wasn't thought through very clearly; certainly the possible effect of
default_tablespace wasn't considered. There's some risk in changing the
behavior of this function, but there are no other call sites in the core
code. Even if it's being used by some third party extension, it's fairly
hard to envision a usage that is okay with a tablespace clause being
appended some of the time but can't handle it being appended all the time.

Back-patch to all supported versions.

Code fix by me, investigation and test cases by Michael Paquier.

Discussion: <1479294998857-5930602(dot)post(at)n3(dot)nabble(dot)com>

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/8f67a6c226a3f73b7115491650630dd8a91937df

Modified Files
--------------
src/backend/utils/adt/ruleutils.c | 23 ++++---
src/test/regress/input/tablespace.source | 31 +++++++++
src/test/regress/output/tablespace.source | 105 ++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2016-11-23 21:26:47 pgsql: Avoid masking a function parameter name with a local variable na
Previous Message Tom Lane 2016-11-23 03:04:37 Re: pgsql: Doc: improve documentation about composite-value usage.