Re: Logical Replication of sequences

From: vignesh C <vignesh21(at)gmail(dot)com>
To: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
Cc: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Euler Taveira <euler(at)eulerto(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
Subject: Re: Logical Replication of sequences
Date: 2025-08-06 08:57:57
Message-ID: CALDaNm05eFK4vB6pihNHVoob9412eQjzCeuP5vVK1EutAZ+B+Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 1 Aug 2025 at 16:18, Hayato Kuroda (Fujitsu)
<kuroda(dot)hayato(at)fujitsu(dot)com> wrote:
>
> Dear Vignesh,
>
> I played with your patch and found something.
>
> 01.
> In LogicalRepSyncSequences() and GetSubscriptionRelations(), there is a possibility
> that the sequence on the subscriber could be dropped before opens that.
> This can cause `could not open relation with OID %u` error, which is not user-friendly.
> Can we avoid that? Even if it is difficult we should add ereport().

Addressed this by taking RowExclusiveLock on the sequence while
preparing the list

> 02.
> ```
> /*
> * Check that our sequencesync worker has permission to insert into
> * the target sequence.
> */
> aclresult = pg_class_aclcheck(RelationGetRelid(sequence_rel), GetUserId(),
> ACL_INSERT);
> if (aclresult != ACLCHECK_OK)
> aclcheck_error(aclresult,
> get_relkind_objtype(sequence_rel->rd_rel->relkind),
> seqname);
> ```
>
> Hmm, but upcoming SetSequence() needs UPDATE privilege. I feel it should be checked.

Modified

> 03.
> Similar with 1, sequences can be dropped just before entering copy_sequences().
> This can cause `cache lookup failed for sequence` error, which cannot be translated.
> Can we avoid that or change the error-function to erport()?

Changed it to log this sequence concurrently dropped

> 04.
> ```
> if (message_level_is_interesting(DEBUG1))
> ereport(DEBUG1,
> errmsg_internal("logical replication synchronization for subscription \"%s\", sequence \"%s.%s\" has finished",
> MySubscription->name,
> seqinfo->nspname,
> seqinfo->seqname));
> ```
>
> I feel no need to add if-statement because we do not touch additional data here.

Modified

> 05.
> ```
> list_free_deep(sequences_to_copy);
> ```
>
> IIUC, this function free's each elements and list itself, but they do no-op for
> attributes of elements. Can we pfree() for seqname and nspname?

Modified

The attached v20250806 version patch has the changes for the same.

Regards,
Vignesh

Attachment Content-Type Size
v20250806-0003-Reorganize-tablesync-Code-and-Introduce-sy.patch text/x-patch 24.6 KB
v20250806-0004-Introduce-REFRESH-PUBLICATION-SEQUENCES-fo.patch text/x-patch 43.3 KB
v20250806-0001-Enhance-pg_get_sequence_data-function.patch text/x-patch 7.3 KB
v20250806-0005-New-worker-for-sequence-synchronization-du.patch text/x-patch 85.6 KB
v20250806-0002-Introduce-ALL-SEQUENCES-support-for-Postgr.patch text/x-patch 109.1 KB
v20250806-0006-Documentation-for-sequence-synchronization.patch text/x-patch 34.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-08-06 09:09:35 Re: Remove INT64_HEX_FORMAT and UINT64_HEX_FORMAT
Previous Message Bertrand Drouvot 2025-08-06 08:39:24 Re: Improve LWLock tranche name visibility across backends