Hi everybody,

Thanks for pointing that out.

Yes, this is an updated version of the patch. I've addressed the missing
regression test changes by updating 'expected/cluster.out' as well.

The patch now includes:

   - the 'PreventInTransactionBlock()' check for 'REPACK (ANALYZE)';
   - the regression test in 'cluster.sql'; and
   - the corresponding expected output in 'expected/cluster.out'

I also verified that the regression tests 'test_setup' and cluster pass,
and that the patch applies cleanly to a clean worktree.

The updated patch is attached.

With Regards,
Osama Abdul Qader

On Thu, Sep 3, 2026 at 12:43 PM Osama Abdul Qader <
[email protected]> wrote:

> Hi Antonin and Everyone,
>
> Greetings of the day,
>
> I'll look into the issues mentioned in [1] and [2], including the missing
> regression test changes in 'expected/cluster.out', and prepare an updated
> patch.
>
> With best regards,
> Osama Abdul Qader
>
> On Thu, Sep 3, 2026 at 10:12 AM Antonin Houska <[email protected]> wrote:
>
>> Osama Abdul Qader <[email protected]> wrote:
>>
>> > I have prepared a patch that rejects REPACK (ANALYZE) with
>> PreventInTransactionBlock(), consistent with the existing restriction for
>> > REPACK (CONCURRENTLY). I also added a regression test covering
>> execution inside a transaction block.
>> >
>> > The patch applies cleanly to the current tree and passes git diff
>> --check.
>>
>> Is this a new version of [1]? If so, I'm not sure it addresses all the
>> problems mentioned in [2]. And regarding regression tests, it misses the
>> changes in expected/cluster.out.
>>
>>
>> [1] https://www.postgresql.org/message-id/49398.1787944525%40localhost
>> [2]
>> https://www.postgresql.org/message-id/CAHGQGwEezdMUixhJ-N0YO0OFUmh0uPaXRDkds5FS-5dmdwz4Bg%40mail.gmail.com
>>
>> --
>> Antonin Houska
>> Web: https://www.cybertec-postgresql.com
>>
>
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index edff54e734e..fac4e12c13c 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -314,6 +314,16 @@ ExecRepack(ParseState *pstate, RepackStmt *stmt, bool isTopLevel)
 		PreventInTransactionBlock(isTopLevel, "REPACK (CONCURRENTLY)");
 	}
 
+	else if ((params.options & CLUOPT_ANALYZE) != 0)
+	{
+		/*
+		 * REPACK (ANALYZE) performs transaction management internally.
+		 * It therefore cannot be executed inside a transaction block or
+		 * from a function or procedure.
+		 */
+		PreventInTransactionBlock(isTopLevel, "REPACK (ANALYZE)");
+	}
+
 	/*
 	 * If a single relation is specified, process it and we're done ... unless
 	 * the relation is a partitioned table, in which case we fall through.
diff --git a/src/test/regress/expected/cluster.out b/src/test/regress/expected/cluster.out
index d1bc8a13286..36dd1f3804c 100644
--- a/src/test/regress/expected/cluster.out
+++ b/src/test/regress/expected/cluster.out
@@ -796,6 +796,11 @@ ORDER BY 1;
  clstr_tst_pkey
 (3 rows)
 
+-- REPACK (ANALYZE) must not be executed inside a transaction block
+BEGIN;
+REPACK (ANALYZE) clstr_tst;
+ERROR:  REPACK (ANALYZE) cannot run inside a transaction block
+ROLLBACK;
 -- Verify partial analyze works
 REPACK (ANALYZE) clstr_tst (a);
 REPACK (ANALYZE) clstr_tst;
diff --git a/src/test/regress/sql/cluster.sql b/src/test/regress/sql/cluster.sql
index e7a62367adf..cb170731147 100644
--- a/src/test/regress/sql/cluster.sql
+++ b/src/test/regress/sql/cluster.sql
@@ -380,6 +380,10 @@ INSERT INTO clstr_tst (b, c) VALUES (1111, 'this should fail');
 SELECT conname FROM pg_constraint WHERE conrelid = 'clstr_tst'::regclass
 ORDER BY 1;
 
+-- REPACK (ANALYZE) must not be executed inside a transaction block
+BEGIN;
+REPACK (ANALYZE) clstr_tst;
+ROLLBACK;
 -- Verify partial analyze works
 REPACK (ANALYZE) clstr_tst (a);
 REPACK (ANALYZE) clstr_tst;

Reply via email to