postgres.git / summary / log / commit / refs

commit    c84243d5b484b0a672664fcfaeeac22204887423
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Wed Oct 07 01:39:15 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 d7fb16d3c85..843cc502f65 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -216,6 +216,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 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( [parent: 4f1751879d34]