From 23e8eb7938546a6b8e767e2ec15c8b3e5315a127 Mon Sep 17 00:00:00 2001 From: reshke Date: Tue, 6 Oct 2026 09:50:11 +0300 Subject: [PATCH v1] reindexdb: error out on index-level REINDEX with CONCURRENTLY and multiple jobs reindexdb batches the REINDEX commands of all indexes attached to the same table into a single multi-statement query when using multiple jobs, an oversight of 47f99a407d. Such a query fails with REINDEX CONCURRENTLY, as it cannot run inside the implicit transaction block created for the multi-statement query, and batching cannot be avoided here because the indexes of one table have to be reindexed one at a time to avoid conflicts across jobs. So, error out on this combination instead of attempting a fix. --- src/bin/scripts/reindexdb.c | 8 ++++++++ src/bin/scripts/t/090_reindexdb.pl | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index d7fb16d3c85..680a657a37d 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -360,6 +360,14 @@ reindex_one_database(ConnParams *cparams, ReindexType type, case REINDEX_INDEX: Assert(user_list != NULL); + /* + * Batching the indexes of one table into a single + * multi-statement query does not work with CONCURRENTLY, so + * refuse the combination. + */ + if (concurrently) + pg_fatal("cannot use multiple jobs to reindex indexes concurrently"); + /* * Generate a list of indexes and a matching list of table * OIDs, based on the user-specified index names. diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl index ae7d3724464..b78f31b3795 100644 --- a/src/bin/scripts/t/090_reindexdb.pl +++ b/src/bin/scripts/t/090_reindexdb.pl @@ -298,6 +298,16 @@ $node->issues_sql_like( ], qr/statement:\ REINDEX TABLE s1.t1;/, 'parallel reindexdb for schemas does a per-table REINDEX'); +$node->command_fails( + [ + 'reindexdb', + '--jobs' => '2', + '--concurrently', + '--index' => 's1.i1', + '--index' => 's2.i2', + 'postgres', + ], + 'parallel reindexdb for indices concurrently'); $node->command_ok([ 'reindexdb', '--jobs' => '2', '--schema' => 's3' ], 'parallel reindexdb with empty schema'); $node->command_ok( -- 2.43.0