postgres.git / summary / log / commit / refs

commit    869c53ff8fe412b0da066d95419753481412a2a4
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Wed Oct 07 01:39:32 2026 +0000
First released in: 17.12, 18.7, 19.0

    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 <reshkekirill@gmail.com>
    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'); [parent: 0fc4077f7f51]