Re: REPACK (ANALYZE) within transaction block segfaults

From: Antonin Houska <ah(at)cybertec(dot)at>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, alvherre(at)kurilemu(dot)de
Subject: Re: REPACK (ANALYZE) within transaction block segfaults
Date: 2026-08-28 19:15:25
Message-ID: 49398.1787944525@localhost
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nathan Bossart <nathandbossart(at)gmail(dot)com> wrote:

> On Fri, Aug 28, 2026 at 01:09:59AM +0900, Fujii Masao wrote:
> > On Thu, Aug 27, 2026 at 10:56 PM Nathan Bossart
> > <nathandbossart(at)gmail(dot)com> wrote:
> >> Presumably we need to handle transaction blocks a bit like how vacuum()
> >> does. Or maybe even prevent REPACK (ANALYZE) within a transaction block.
> >
> > I looked into this a bit. I think the problem is not ordinary
> > transaction blocks themselves, but non-top-level execution, such as the
> > DO block in the reproducer.
> >
> > So the attached patch rejects only non-top-level REPACK (ANALYZE)
> > commands.
>
> Hm. Couldn't we do something like the in_outer_xact/use_own_xacts stuff in
> vacuum() to get it working instead?

I think there are just two different concepts (for historical reasons?):
vacuum_rel() expects no active transaction on entry, while cluster_rel()
handles transaction boundaries on its own.

Since REPACK (ANALYZE) is effectively VACUUM (FULL, ANALYZE), I'd prefer the
same behavior, i.e. prohibiting execution both in a transaction block and in a
function:

postgres=# BEGIN; VACUUM (FULL, ANALYZE) t; END;
BEGIN
ERROR: VACUUM cannot run inside a transaction block
ROLLBACK

postgres=# DO $$ BEGIN EXECUTE 'VACUUM (FULL, ANALYZE) t'; END $$;
ERROR: VACUUM cannot be executed from a function or procedure
CONTEXT: SQL statement "VACUUM (FULL, ANALYZE) t"
PL/pgSQL function inline_code_block line 1 at EXECUTE

postgres=# BEGIN; REPACK (ANALYZE) t; END;
BEGIN
ERROR: REPACK (ANALYZE) cannot run inside a transaction block
ROLLBACK

postgres=# DO $$ BEGIN EXECUTE 'REPACK (ANALYZE) t'; END $$;
ERROR: REPACK (ANALYZE) cannot be executed from a function or procedure
CONTEXT: SQL statement "REPACK (ANALYZE) t"
PL/pgSQL function inline_code_block line 1 at EXECUTE

The attached patch does that.

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

Attachment Content-Type Size
0001-Do-not-allow-REPACK-ANALYZE-in-function-and-in-trans.patch text/x-diff 1.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2026-08-28 19:27:44 extendable psql?
Previous Message Masahiko Sawada 2026-08-28 19:15:02 Re: pg_stat_get_autovacuum_scores ignores the main table's reloptions for TOAST tables