[PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

Started by Baji Shaik6 months ago9 messageshackers
Jump to latest
#1Baji Shaik
baji.pgdev@gmail.com

Hi,

While exploring the new REPACK (CONCURRENTLY) feature, I noticed
a few user-facing error paths that could be made more accurate.
Patch series of three:

0001 -- When wal_level < replica, REPACK (CONCURRENTLY) currently
surfaces generic "replication slots ... wal_level" error
from CheckSlotRequirements(), with a CONTEXT line referring
to an internal worker. Add an upfront check that reports a
REPACK-specific error.

0002 -- check_concurrent_repack_requirements() reports the same
generic "no identity index" error for several distinct
cases, two of which are misleading: REPLICA IDENTITY FULL
(which is set, but the hint says there is no identity), and
a deferrable PK as the only identity (skipped per commit
832e220d99a, but the hint suggests adding an index that
already exists). Distinguish these cases.

0003 -- Four ereport(ERROR) calls in the REPACK CONCURRENTLY code
path lack errcode() and default to ERRCODE_INTERNAL_ERROR.
Add appropriate errcodes; in particular, the
apply_concurrent_update/delete failures map cleanly to
ERRCODE_T_R_SERIALIZATION_FAILURE.

All three are error-path only; the success path is unchanged. Each
patch is independently committable. Detailed rationale is in the
individual commit messages.

Tested with `make check` (245/245 pass) and `make isolation/check`
(128/128 pass) on top of master; 0002 also updates
src/test/regress/expected/cluster.out to match the new deferrable-PK
message.

Thanks,
Baji Shaik

Attachments:

0003-Add-missing-errcode-to-REPACK-CONCURRENTLY-ereport-c.patchapplication/octet-stream; name=0003-Add-missing-errcode-to-REPACK-CONCURRENTLY-ereport-c.patchDownload+8-3
0002-Improve-REPACK-CONCURRENTLY-errors-for-unusable-iden.patchapplication/octet-stream; name=0002-Improve-REPACK-CONCURRENTLY-errors-for-unusable-iden.patchDownload+32-3
0001-Improve-REPACK-CONCURRENTLY-error-when-wal_level-rep.patchapplication/octet-stream; name=0001-Improve-REPACK-CONCURRENTLY-error-when-wal_level-rep.patchDownload+13-1
#2Chao Li
li.evan.chao@gmail.com
In reply to: Baji Shaik (#1)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

On May 27, 2026, at 11:06, Baji Shaik <baji.pgdev@gmail.com> wrote:

Hi,

While exploring the new REPACK (CONCURRENTLY) feature, I noticed
a few user-facing error paths that could be made more accurate.
Patch series of three:

0001 -- When wal_level < replica, REPACK (CONCURRENTLY) currently
surfaces generic "replication slots ... wal_level" error
from CheckSlotRequirements(), with a CONTEXT line referring
to an internal worker. Add an upfront check that reports a
REPACK-specific error.

LGTM

0002 -- check_concurrent_repack_requirements() reports the same
generic "no identity index" error for several distinct
cases, two of which are misleading: REPLICA IDENTITY FULL
(which is set, but the hint says there is no identity), and
a deferrable PK as the only identity (skipped per commit
832e220d99a, but the hint suggests adding an index that
already exists). Distinguish these cases.

When I was working on 832e220d99a, I actually considered for more detailed error messages, but I ended up giving up. I think we should be careful about adding more branches here unless the existing message is causing significant confusion in practice.

So, I personally don’t like 0002.

0003 -- Four ereport(ERROR) calls in the REPACK CONCURRENTLY code
path lack errcode() and default to ERRCODE_INTERNAL_ERROR.
Add appropriate errcodes; in particular, the
apply_concurrent_update/delete failures map cleanly to
ERRCODE_T_R_SERIALIZATION_FAILURE.

LGTM

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#3Baji Shaik
baji.pgdev@gmail.com
In reply to: Chao Li (#2)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

Hi Chao,

Thanks for the quick review and feedback.

On Wed, May 27, 2026 at 1:50 AM Chao Li <li.evan.chao@gmail.com> wrote:

On May 27, 2026, at 11:06, Baji Shaik <baji.pgdev@gmail.com> wrote:

When I was working on 832e220d99a, I actually considered for more detailed
error messages, but I ended up giving up. I think we should be careful
about adding more branches here unless the existing message is causing
significant confusion in practice.

So, I personally don’t like 0002.

I hear the concern of adding more branches here. FWIW, neither the
deferrable PK limitation nor the REPLICA IDENTITY FULL case is
documented in repack.sgml, and the current error message doesn't
surface either issue. The user has no way to discover what's wrong
without reading the source. That's why I think the improved messages
are warranted here. Happy to add a documentation note as well, or
both. Let me know what's preferred.

But happy to drop 0002 if others feel the same. 0001 and 0003 stand on
their own.

Thanks,
Baji Shaik

#4Alvaro Herrera
alvherre@kurilemu.de
In reply to: Chao Li (#2)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

On 2026-May-27, Chao Li wrote:

On May 27, 2026, at 11:06, Baji Shaik <baji.pgdev@gmail.com> wrote:

0001 -- When wal_level < replica, REPACK (CONCURRENTLY) currently
surfaces generic "replication slots ... wal_level" error
from CheckSlotRequirements(), with a CONTEXT line referring
to an internal worker. Add an upfront check that reports a
REPACK-specific error.

LGTM

Pushed this one earlier. I changed the errcode though, because in my
mind "object" is a database object, and the server configuration is not
an object. So I used INVALID_PARAMETER_VALUE instead. I also don't
think it makes sense to say "cannot repack table X", so the user leaves
thinking they could repack table Y instead. The whole point being that
you cannot vacuum _any_ tables. So I made the errmsg() say that.

When I was working on 832e220d99a, I actually considered for more
detailed error messages, but I ended up giving up. I think we should
be careful about adding more branches here unless the existing message
is causing significant confusion in practice.

So, I personally don’t like 0002.

I'll give this a look after some icecream.

0003 -- Four ereport(ERROR) calls in the REPACK CONCURRENTLY code
path lack errcode() and default to ERRCODE_INTERNAL_ERROR.
Add appropriate errcodes; in particular, the
apply_concurrent_update/delete failures map cleanly to
ERRCODE_T_R_SERIALIZATION_FAILURE.

Also pushed, with additional editorialization. I have recollections of
out message policy saying something about "could not do X" instead of
"failed to do X", so I changed it that way. (But I couldn't find that
in the style guide.)

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/

#5Alvaro Herrera
alvherre@kurilemu.de
In reply to: Chao Li (#2)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

On 2026-May-27, Chao Li wrote:

0002 -- check_concurrent_repack_requirements() reports the same
generic "no identity index" error for several distinct
cases, two of which are misleading: REPLICA IDENTITY FULL
(which is set, but the hint says there is no identity), and
a deferrable PK as the only identity (skipped per commit
832e220d99a, but the hint suggests adding an index that
already exists). Distinguish these cases.

When I was working on 832e220d99a, I actually considered for more
detailed error messages, but I ended up giving up. I think we should
be careful about adding more branches here unless the existing message
is causing significant confusion in practice.

I pushed this one too (well, something close to it anyway), because I
think the replica identity issue could be an (unnecessary) usability
tripwire.

I'm curious to know why you gave up on this, if you want to share more.

Thanks both,

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Voy a acabar con todos los humanos / con los humanos yo acabaré
voy a acabar con todos (bis) / con todos los humanos acabaré ¡acabaré! (Bender)

#6Alvaro Herrera
alvherre@kurilemu.de
In reply to: Alvaro Herrera (#5)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

While looking these patches over I noticed that we still have some error
reports cases uncovered. Here's a quick attempt to try and complete
that.

After this patch I see only one uncovered error path, the one that
prevents repacking a temp table of another session. That would require
an isolation test. Not sure it's worth the trouble ... (There's a
bunch of uncovered "elog(ERROR)" cases, but those are mostly just
can't-happen conditions, as I understand).

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/

Attachments:

0001-Cover-some-errors-and-corner-conditions-in-repack.c.patchtext/x-diff; charset=utf-8Download+61-1
#7Baji Shaik
baji.pgdev@gmail.com
In reply to: Alvaro Herrera (#6)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

On Thu, May 28, 2026 at 4:18 PM Álvaro Herrera <alvherre@kurilemu.de> wrote:

While looking these patches over I noticed that we still have some error
reports cases uncovered. Here's a quick attempt to try and complete
that.

After this patch I see only one uncovered error path, the one that
prevents repacking a temp table of another session. That would require
an isolation test. Not sure it's worth the trouble ... (There's a
bunch of uncovered "elog(ERROR)" cases, but those are mostly just
can't-happen conditions, as I understand).

LGTM, thanks for adding these.

FWIW I see a couple more uncovered ereport(ERROR) paths 1/ invalid
index (line 813) 2/ shared catalog with USING INDEX (line 580,
needs allow_system_table_mods). But both need unusual setup, so
fine to leave them along with the temp table one.

Thanks,
Baji Shaik.

#8Chao Li
li.evan.chao@gmail.com
In reply to: Alvaro Herrera (#5)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

On May 29, 2026, at 02:35, Álvaro Herrera <alvherre@kurilemu.de> wrote:

On 2026-May-27, Chao Li wrote:

0002 -- check_concurrent_repack_requirements() reports the same
generic "no identity index" error for several distinct
cases, two of which are misleading: REPLICA IDENTITY FULL
(which is set, but the hint says there is no identity), and
a deferrable PK as the only identity (skipped per commit
832e220d99a, but the hint suggests adding an index that
already exists). Distinguish these cases.

When I was working on 832e220d99a, I actually considered for more
detailed error messages, but I ended up giving up. I think we should
be careful about adding more branches here unless the existing message
is causing significant confusion in practice.

I pushed this one too (well, something close to it anyway), because I
think the replica identity issue could be an (unnecessary) usability
tripwire.

I'm curious to know why you gave up on this, if you want to share more.

Sure. As the committed version is slightly different from the original patch, my comments below are still based on the original patch:

1. I am not against improving the error message in principle, but I'm worried about the maintainability of distinguishing all the possible reasons here.

GetRelationIdentityOrPK() currently returns InvalidOid for several cases, so the patch tries to infer the reason afterwards from relreplident, rd_ispkdeferrable, rd_pkindex, etc. That works for the current cases, but it also means that whenever the REPACK (CONCURRENTLY) requirements change, these extra checks may need to be revisited. For example, if FULL is supported in the future, the FULL specific error would need to be removed or changed.

2. I also think the hint for the deferrable primary key case may be too specific:
```
Use ALTER TABLE ... ALTER CONSTRAINT to make the primary key NOT DEFERRABLE, or use ALTER TABLE ... REPLICA IDENTITY USING INDEX to designate another index.
```

Those are useful suggestions in many cases, but they are not necessarily the only possible solutions. So I was not sure if we should provide such a specific hint.

3. Especially for the FULL check, I have a pending patch [1]/messages/by-id/CAEoWx2mMorbMwjKbT4YCsjDyL3r9Mp+z0bbK57VZ+OkJTgJQVQ@mail.gmail.com that may potentially allow REPLICA_IDENTITY_DEFAULT to fall back to FULL. If something like that eventually happens, this kind of detailed check could become misleading. My general concern is that the more detailed we make these inferred errors, the more fragile they may become when future behavior changes.

BTW, for patch [1]/messages/by-id/CAEoWx2mMorbMwjKbT4YCsjDyL3r9Mp+z0bbK57VZ+OkJTgJQVQ@mail.gmail.com, this is not an imagined feature. The requirement came from real customer operations. So, Álvaro, if you could help there, I would greatly appreciate it. That is a long thread, so no rush.

[1]: /messages/by-id/CAEoWx2mMorbMwjKbT4YCsjDyL3r9Mp+z0bbK57VZ+OkJTgJQVQ@mail.gmail.com

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#9Alvaro Herrera
alvherre@kurilemu.de
In reply to: Baji Shaik (#7)
Re: [PATCH] Improve REPACK (CONCURRENTLY) error messages for unsupported configurations

On 2026-05-29, Baji Shaik wrote:

LGTM, thanks for adding these.

FWIW I see a couple more uncovered ereport(ERROR) paths 1/ invalid
index (line 813) 2/ shared catalog with USING INDEX (line 580,
needs allow_system_table_mods). But both need unusual setup, so
fine to leave them along with the temp table one.

Yeah. I think we could still cover the one in line 580, maybe in test_decoding, but I didn't try. I'm not as excited about this one though; I'm ok to leave it as-is. Anyway, I have pushed the patch, together with moving some previous tests to test_decoding, because the error message added by your initial 0001 caused wal_level=minimal tests to fail, as shown by thorntail
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=thorntail&dt=2026-05-29%2006%3A31%3A03

Thanks!

--
Álvaro Herrera