pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Pin relations in phase 1 of REINDEX CONCURRENTLY
Date: Fri, 20 Nov 2026 04:47:02 +0000
Message-ID: <E1xUGWb-00000000TEF-0D8w@gemulon.postgresql.org> (raw)

Pin relations in phase 1 of REINDEX CONCURRENTLY

Phase 1 of ReindexRelationConcurrently() evaluates index expressions and
predicates when computing the safety of each index and when creating the
definition of each new index.  These may call functions run as the table
owner.

The old and new indexes processed in the previous iterations of the loop
were closed at this stage.  Hence, a function was able to drop one of
them or reindex one of the new indexes, leading to an assertion failure
in the build phase, or to an internal error with a dropped index
committed.

The relations opened in phase 1 are now kept opened until the session
locks are taken, so as DDLs on them are blocked by CheckTableNotInUse().
The build and validation phases already pin the relations, and the
protections in build phase limit the damage to an ERROR.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Shihao Zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/aver6A1EQEd2FaKq@paquier.xyz
Backpatch-through: 15

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9e612947eac3a296660823210db1881ad0819960

Modified Files
--------------
src/backend/commands/indexcmds.c           | 28 ++++++++++++++++++----
src/test/regress/expected/create_index.out | 37 +++++++++++++++++++++++++++++-
src/test/regress/sql/create_index.sql      | 26 ++++++++++++++++++++-
3 files changed, 84 insertions(+), 7 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1xUGWb-00000000TEF-0D8w@gemulon.postgresql.org>
Permalink:  ../E1xUGWb-00000000TEF-0D8w@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xUGWb-00000000TEF-0D8w@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Pin relations in phase 1 of REINDEX CONCURRENTLY
  In-Reply-To: <E1xUGWb-00000000TEF-0D8w@gemulon.postgresql.org>
  References: <E1xUGWb-00000000TEF-0D8w@gemulon.postgresql.org>

* 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