Preserve tablespace of exclusion constraint indexes in ALTER TYPE

Started by 신성준2 days ago4 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1신성준
shinsj4653@gmail.com

Hi hackers,

When ALTER TABLE ... ALTER COLUMN TYPE rebuilds an exclusion
constraint, its index loses the tablespace given with USING INDEX
TABLESPACE. If the index storage is reused because no rewrite is
needed, the index can't be opened afterwards:

SET allow_in_place_tablespaces = on;
CREATE TABLESPACE ts LOCATION '';
CREATE TABLE t (b varchar(5),
EXCLUDE USING btree (b WITH =) USING INDEX TABLESPACE ts);
INSERT INTO t VALUES ('y');
ALTER TABLE t ALTER b TYPE varchar(10);
INSERT INTO t VALUES ('w');
ERROR: could not open file "base/5/16388": No such file or directory

The constraint is rebuilt from pg_get_constraintdef_command(), which
prints the tablespace for primary key and unique constraints but not
for exclusion constraints. The attached patch prints it for those too
when a full command is requested, so pg_get_constraintdef() and pg_dump
are not affected.

Best regards,
Seongjun Shin

Attachments:

t259873_1
v1-0001-Preserve-tablespace-of-exclusion-constraint-index.patchapplication/octet-stream; name=v1-0001-Preserve-tablespace-of-exclusion-constraint-index.patchDownload+48-3
#2Osama Abdul Qader
osamaabdulqaderpostgres@gmail.com
In reply to: 신성준 (#1)
Re: Preserve tablespace of exclusion constraint indexes in ALTER TYPE

Hi 신성준,

On Thu, 26 Nov, 2026, 6:47 pm 신성준, <shinsj4653@gmail.com> wrote:

Hi hackers,

When ALTER TABLE ... ALTER COLUMN TYPE rebuilds an exclusion
constraint, its index loses the tablespace given with USING INDEX
TABLESPACE. If the index storage is reused because no rewrite is
needed, the index can't be opened afterwards:

SET allow_in_place_tablespaces = on;
CREATE TABLESPACE ts LOCATION '';
CREATE TABLE t (b varchar(5),
EXCLUDE USING btree (b WITH =) USING INDEX TABLESPACE ts);
INSERT INTO t VALUES ('y');
ALTER TABLE t ALTER b TYPE varchar(10);
INSERT INTO t VALUES ('w');
ERROR: could not open file "base/5/16388": No such file or directory

The constraint is rebuilt from pg_get_constraintdef_command(), which
prints the tablespace for primary key and unique constraints but not
for exclusion constraints. The attached patch prints it for those too
when a full command is requested, so pg_get_constraintdef() and pg_dump
are not affected.

Best regards,
Seongjun Shin

I'm interested in reviewing it. I hope for the best.

Best regards,
Osama Abdul Qader.

Show quoted text
#3신성준
shinsj4653@gmail.com
In reply to: Osama Abdul Qader (#2)
Re: Preserve tablespace of exclusion constraint indexes in ALTER TYPE

Hi Osama,

Thank you for your interest in reviewing this patch as well.

I have registered it in the Commitfest, and you can find the entry here:
https://commitfest.postgresql.org/patch/7727/

I appreciate your help and look forward to any feedback you may have.

Best regards,
Seongjun Shin

#4Osama Abdul Qader
osamaabdulqaderpostgres@gmail.com
In reply to: 신성준 (#3)
Re: Preserve tablespace of exclusion constraint indexes in ALTER TYPE

Hi again,

On Fri, 27 Nov 2026 at 05:20, 신성준 <shinsj4653@gmail.com> wrote:

Hi Osama,

Thank you for your interest in reviewing this patch as well.

I have registered it in the Commitfest, and you can find the entry here:
https://commitfest.postgresql.org/patch/7727/

I appreciate your help and look forward to any feedback you may have.

Best regards,
Seongjun Shin

I've successfully reviewed patch v1.

The patch looks good to me. Passing `fullCommand` as the `showTblSpc`
argument ensures that the tablespace clause is included when generating the
internal full constraint command, while keeping the public
`pg_get_constraintdef()` output unchanged.

The regression test in `tablespace.sql` also covers the exclusion
constraint's tablespace preservation across the ALTER COLUMN TYPE
operations.

I've tested the patch locally:

- Builds PostgreSQL using `make -j$(nproc)` successfully.
- `make check` passed all 239 regression test cases successfully.

I couldn't identify any blocking issues. The patch looks good to me, and
I've added myself as a reviewer on commitfest.

Best regards,
Osama Abdul Qader.