RE: [PATCH] Support automatic sequence replication
Zhijie Hou (Fujitsu) <houzj.fnst@fujitsu.com>
From: "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>
To: Amit Kapila <amit.kapila16@gmail.com>, Ajin Cherian <itsajin@gmail.com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, shveta malik <shveta.malik@gmail.com>, Ashutosh Sharma <ashu.coek88@gmail.com>, PostgreSQL
Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-02-28T08:40:31Z
Lists: pgsql-hackers
Attachments
- v8-0001-Support-automatic-sequence-replication.patch (application/octet-stream) patch v8-0001
- v8-0002-Synchronize-sequences-directly-in-REFRESH-SEQUENC.patch (application/octet-stream) patch v8-0002
On Friday, February 27, 2026 7:07 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> Few comments:
> =============
> 1.
> + oldctx = MemoryContextSwitchTo(SequenceSyncContext);
>
> - initStringInfo(&app_name);
> - appendStringInfo(&app_name, "pg_%u_sequence_sync_" UINT64_FORMAT,
> - MySubscription->oid, GetSystemIdentifier());
> + /* Process sequences */
> + sequence_copied = copy_sequences(conn, seqinfos);
>
> - /*
> - * Establish the connection to the publisher for sequence synchronization.
> - */
> - LogRepWorkerWalRcvConn =
> - walrcv_connect(MySubscription->conninfo, true, true,
> - must_use_password,
> - app_name.data, &err);
> - if (LogRepWorkerWalRcvConn == NULL)
> - ereport(ERROR,
> - errcode(ERRCODE_CONNECTION_FAILURE),
> - errmsg("sequencesync worker for subscription \"%s\" could not connect to
> the publisher: %s",
> - MySubscription->name, err));
> -
> - pfree(app_name.data);
> -
> - copy_sequences(LogRepWorkerWalRcvConn);
> + MemoryContextSwitchTo(oldctx);
>
> It is better to switch to SequenceSyncContext at the caller of
> LogicalRepSyncSequences similar to what we are doing for
> ApplyMessageContext.
Agreed. I changed as suggested.
>
> 2.
> @@ -4221,6 +4221,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
> ProcessConfigFile(PGC_SIGHUP);
> }
>
> +
> if (rc & WL_TIMEOUT)
>
> Spurious line addition.
>
> 3. Apart from above, the attached patch contains comments and cosmetic
> changes.
Thanks for the patch, I have merged them into 0001.
Here is the V8 patch set addressing the previous review comments:
- For 0001, I noticed that the GetSequence() function added in the patch
fetches the local sequence value without any privilege check. This
allows the worker to read sequence data even without proper SELECT
privilege, which seems unsafe. I've added a SELECT privilege check
before fetching the sequence value. Additionally, I've updated several
comments, made cosmetic changes, commit message update, and run
pgindent on all patches.
- 0002 includes the changes to synchronize sequences directly in the
REFRESH SEQUENCES command
Best Regards,
Hou zj
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Don't include wait_event.h in pgstat.h
- 868825aaeb40 19 (unreleased) cited
-
Don't include proc.h in shm_mq.h
- a2c89835f512 19 (unreleased) cited
-
Fix unsafe RTE_GROUP removal in simplify_EXISTS_query
- 77c7a17a6e5f 19 (unreleased) cited
-
Add sequence synchronization for logical replication.
- 5509055d6956 19 (unreleased) cited