Re: Fix publisher-side sequence permission reporting

From: vignesh C <vignesh21(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Tristan Partin <tristan(at)partin(dot)io>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix publisher-side sequence permission reporting
Date: 2026-07-16 08:52:27
Message-ID: CALDaNm2XTbe+gQVQqfGXR2zr2kPiUj9DAryH_gEyueZ5h7DeAQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 15 Jul 2026 at 18:34, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
> On Mon, Jul 13, 2026 at 9:48 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
> > I've attached a patch to handle this case by treating a 'NULL'
> > privilege value as indicating that the sequence no longer exists and
> > reporting it through the existing "missing sequence on publisher"
> > path.
> > Thoughts?
>
> Thanks for the patch!
> It looks good to me overall. I just have a couple of minor comments.
>
>
> remote_has_select_priv = DatumGetBool(slot_getattr(slot, ++col, &isnull));
> - Assert(!isnull);
> + if (isnull)
> + return COPYSEQ_SKIPPED;
>
> Isn't it be better to call DatumGetBool() after checking isnull,
> similar to how we handle seqinfo_local->last_value?
>
>
> - * The remote sequence state can be NULL if the publisher lacks the
> - * required privileges or if the sequence was dropped concurrently after
> - * it was identified in the catalog snapshot (see pg_get_sequence_data()).
>
> I think it's worth keeping this comment. How about something like
> applying the following based on your patch?
>
> ----------------------------------------------
> /*
> * has_sequence_privilege() itself returns NULL, rather than false, when
> * the sequence has been dropped concurrently after it was identified in
> - * the catalog snapshot (see has_sequence_privilege_id()). Treat that the
> - * same as the concurrent-drop case detected via the data columns below,
> - * rather than misreporting it as an insufficient-privilege failure.
> + * the catalog snapshot (see has_sequence_privilege_id()). Treat that as
> + * a missing sequence on the publisher.
> */
> - remote_has_select_priv = DatumGetBool(slot_getattr(slot, ++col, &isnull));
> + datum = slot_getattr(slot, ++col, &isnull);
> if (isnull)
> return COPYSEQ_SKIPPED;
> + remote_has_select_priv = DatumGetBool(datum);
>
> + /*
> + * The remote sequence state can be NULL if the publisher lacks the
> + * required privileges or if the sequence was dropped concurrently after
> + * it was identified in the catalog snapshot (see pg_get_sequence_data()).
> + */
> datum = slot_getattr(slot, ++col, &isnull);
> if (isnull)
> return remote_has_select_priv ? COPYSEQ_SKIPPED :
> ----------------------------------------------

Your suggested changes look good to me, here is an updated v2 version
patch with the changes. I have also verified that Zsolt's test at [1]
also passes with the attached patch.
[1] - https://www.postgresql.org/message-id/CAN4CZFPfmF%3DEpT-9YOKYYzptPt5Q7D5xV-v_RrncbfsSZOAcDw%40mail.gmail.com

Regards,
Vignesh

Attachment Content-Type Size
v2-0001-Fix-sequence-synchronization-for-concurrently-dro.patch application/octet-stream 4.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-07-16 08:55:56 Re: using index to speedup add not null constraints to a table
Previous Message Peter Smith 2026-07-16 08:34:13 Re: Support EXCEPT for TABLES IN SCHEMA publications