From 869c53ff8fe412b0da066d95419753481412a2a4 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 7 Oct 2026 10:39:32 +0900 Subject: [PATCH] reindexdb: Forbid 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, as two steps with query "gen" and "run". Such a query fails with REINDEX CONCURRENTLY, as this command cannot run inside a transaction block. Batching cannot be avoided because the indexes of one table have to be re-indexed one at a time to avoid conflicts across jobs. Let's error out cleanly on the reindexdb side if this combination of options is used, instead of having the server complain about that. This case has not been considered by 47f99a407d. If there is interest in supporting this combination of options, the code should be redesigned for this purpose with some better batching, rather than try to use sets of "gen" and "run" routines. As currently written, an index-level reindexdb uses a set of "gen" steps with one final "run" step, which is nice code-wise. (Note: I doubt that that this would be worth the effort.) Author: Kirill Reshke Discussion: https://postgr.es/m/CALdSSPiEkAmS+n7Ea9XDMrLjkbQk=CrB7zw1kcq9B47hfKUhXw@mail.gmail.com Backpatch-through: 17 --- src/bin/scripts/reindexdb.c | 3 +++ src/bin/scripts/t/090_reindexdb.pl | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 2ff16140ad8..5b41d16a49a 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -212,6 +212,9 @@ main(int argc, char *argv[]) if (concurrentCons > 1 && syscatalog) pg_fatal("cannot use multiple jobs to reindex system catalogs"); + if (concurrentCons > 1 && concurrently && indexes.head != NULL) + pg_fatal("cannot use multiple jobs to reindex indexes concurrently"); + if (alldb) { if (dbname) diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl index f02822da218..309c733f179 100644 --- a/src/bin/scripts/t/090_reindexdb.pl +++ b/src/bin/scripts/t/090_reindexdb.pl @@ -260,6 +260,16 @@ $node->issues_sql_like( $node->command_ok( [ 'reindexdb', '-j', '2', '-S', 's3' ], 'parallel reindexdb with empty schema'); +$node->command_fails( + [ + 'reindexdb', + '--jobs' => '2', + '--concurrently', + '--index' => 's1.i1', + '--index' => 's2.i2', + 'postgres', + ], + 'parallel reindexdb for indices concurrently'); $node->command_ok( [ 'reindexdb', '-j', '2', '--concurrently', '-d', 'postgres' ], 'parallel reindexdb on database, concurrently');