Re: Partitioned index marked valid while a partition is pending detach

From: Alvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: shihao zhong <zhong950419(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Partitioned index marked valid while a partition is pending detach
Date: 2026-11-05 08:05:52
Message-ID: auw3hCAIN3vaW8Fw@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-Nov-05, Michael Paquier wrote:

> On Wed, Nov 04, 2026 at 11:54:26PM -0500, shihao zhong wrote:

> > This is a little trick because it did change the behavior, I dont think user
> > want to create an incorrect PK and running FINALIZE first is easy,
> > so I think this is fine to backport.
>
> + if (PartitionHasPendingDetach(pd->oids[i]))
> + ereport(ERROR,
> + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("cannot create index on partitioned table \"%s\"",
> + RelationGetRelationName(rel)),
> + errdetail("Partition \"%s\" has an incomplete detach.",
> + get_rel_name(pd->oids[i])),
> + errhint("Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation.")));
>
> Still returning an error may be better than breaking a tree
> consistency and even worse, break constraints under-the-hood. I am
> not sure if there is a better option here.. Alvaro, what do you
> think?

I think this idea is good generally speaking, but we shouldn't limit it
to create index, but instead apply it to pretty much any DDL that you
want to run on such a table. The risk of inconsistencies is just too
high and there's no functional reason to let users do anything before
finishing that detach.

I'm happy to listen to example scenarios where my argument fails, to
assess if any exceptions are needed.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Por suerte hoy explotó el califont porque si no me habría muerto
de aburrido" (Papelucho)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-11-05 08:12:07 Re: [Bug Report + Patch] File descriptor leak when io_method=io_uring
Previous Message Michael Paquier 2026-11-05 08:04:17 Re: Fix stale column context after COPY FROM conversion errors