BUG #19932: `repack (concurrently)` does not work in `psql` with `AUTOCOMMIT` set to `off`
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
The following bug has been logged on the website:
Bug reference: 19932
Logged by: Philip Hofstetter
Email address: phofstetter@sensational.ch
PostgreSQL version: 19.0
Operating system: macOS, Linux
Description:
Hello,
contrary to `vacuum` and `cluster`, `repack (concurrently)` is not
whitelisted in `psql` to allow to run it without starting a transaction when
autocommit is off.
This means that on a freshly started `psql` with `\set AUTOCOMMIT off`, it's
still possible to issue `vacuum <table>`, but not `repack (concurrently)
<table>` because `psql` will currently open a transaction before sending the
command.
sample:
pilif@[local]=> vacuum m;
VACUUM
Time: 5.870 ms
pilif@[local]=> repack (concurrently) m;
ERROR: REPACK (CONCURRENTLY) cannot run inside a transaction block
Time: 0.097 ms
*pilif@[local]=>
It looks like there's a white-list of commands in `bin/psql/common.c` in
`command_no_begin()` and it's missing the `repack (concurrently)` case.
Thanks
Philip
On 2026-Nov-23, PG Bug reporting form wrote:
contrary to `vacuum` and `cluster`, `repack (concurrently)` is not
whitelisted in `psql` to allow to run it without starting a transaction when
autocommit is off.
It looks like there's a white-list of commands in `bin/psql/common.c` in
`command_no_begin()` and it's missing the `repack (concurrently)` case.
Oh my, I completely forgot about this. I suppose we need to find the
option list, see if either CONCURRENTLY or ANALYZE are in there, and
treat as a command that requires no BEGIN. It should be something like
this, I guess, but there's a problem in that this code may need to deal
with multibyte chars that might confuse the strchr() calls there.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Oh, great altar of passive entertainment, bestow upon me thy discordant images
at such speed as to render linear thought impossible" (Calvin a la TV)
+ if (pg_strncasecmp(option, "concurrently", 12))
+ /* XXX what if it's 'CONCURRENTLY OFF'? */
+ return true;
+ if (pg_strncasecmp(option, "analyze", 7))
+ /* XXX what if it's 'ANALYZE OFF'? */
+ return true;
Isn't also two == 0 missing from there?
+ option = skip_white_space(option);
and a +1 from there, and from the last skip?
And should it handle `repack;` and `repack using index;`?
Hi,
+ if (pg_strncasecmp(option, "concurrently", 12))
+ /* XXX what if it's 'CONCURRENTLY OFF'? */
+ return true;
That’s a good question and the answer is kinda dissatisfying because
in that case, `psql` will not begin the transaction even though it
could (and would without any options) and would thus cause it to be
autocommited.
That would be slightly unexpected, though I agree it’s probably an edge case.
It’s a bit of a shame that psql needs to do a very minimal parsing job
here when the actual parsing (and the decision of whether something
can run in a transaction or not) happens on the server side again and
in a much more thorough way.
Philip
On 2026-Nov-24, Philip Hofstetter wrote:
It’s a bit of a shame that psql needs to do a very minimal parsing job
here when the actual parsing (and the decision of whether something
can run in a transaction or not) happens on the server side again and
in a much more thorough way.
Yeah, I completely agree. This whole thing is IMV a terrible hack and
it would be better if we didn't have to do it at all. (We cannot avoid
it, obviously.) Implementation-wise it's not very convenient to bring
the server-side parser code to the frontend, though :-(
On the other hand, psql has to do other parsing tasks, such as looking
for command-separating semicolons, quotes and things like that. Those
would perhaps also be better handled with the actual parser code. I'm
not volunteering though.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Oh, great altar of passive entertainment, bestow upon me thy discordant images
at such speed as to render linear thought impossible" (Calvin a la TV)
Import Notes
Reply to msg id not found: CAGKNXQH65yFsHpZ+72TW+41WMZGCZhq9D5Y5Mn0A_57b-rPDEQ@mail.gmail.com
=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@kurilemu.de> writes:
On 2026-Nov-24, Philip Hofstetter wrote:
It’s a bit of a shame that psql needs to do a very minimal parsing job
here when the actual parsing (and the decision of whether something
can run in a transaction or not) happens on the server side again and
in a much more thorough way.
Yeah, I completely agree. This whole thing is IMV a terrible hack and
it would be better if we didn't have to do it at all. (We cannot avoid
it, obviously.) Implementation-wise it's not very convenient to bring
the server-side parser code to the frontend, though :-(
Could we get away with whitelisting all variants of REPACK,
rather than expecting psql to know which ones can't be executed
in a transaction? That seems like a recipe for future bugs of
omission, quite aside from parsing difficulties.
regards, tom lane
On 2026-Nov-24, Tom Lane wrote:
Could we get away with whitelisting all variants of REPACK,
rather than expecting psql to know which ones can't be executed
in a transaction? That seems like a recipe for future bugs of
omission, quite aside from parsing difficulties.
Oh, that idea hadn't occurred to me. I suppose the downside is not very
bad: if you're in non-autocommit mode, and run any REPACK without a
previous command, then that repack will run in a separately committed
transaction, instead of the transaction being left open for the next
command. If you really wanted to run a REPACK in a transaction, you can
work around this by doing a manual BEGIN beforehand.
Pushed that way.
Thanks for reporting this,
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
#error "Operator lives in the wrong universe"
("Use of cookies in real-time system development", M. Gleixner, M. Mc Guire)