RE: Logical Replication of sequences

Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>

From: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
To: 'vignesh C' <vignesh21@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>, Nisha Moond <nisha.moond412@gmail.com>, shveta malik <shveta.malik@gmail.com>, Dilip Kumar <dilipbalaut@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>, Peter Smith <smithpb2250@gmail.com>, Shlok Kyal <shlok.kyal.oss@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Euler Taveira <euler@eulerto.com>, Michael Paquier <michael@paquier.xyz>, "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>, "Jonathan S. Katz" <jkatz@postgresql.org>
Date: 2025-08-28T11:37:56Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Doc: Add documentation for sequence synchronization.

  2. Remove unused assignment in CREATE PUBLICATION grammar.

  3. Add seq_sync_error_count to subscription statistics.

  4. Fix few issues in commit 5509055d69.

  5. Add sequence synchronization for logical replication.

  6. Add worker type argument to logical replication worker functions.

  7. Introduce "REFRESH SEQUENCES" for subscriptions.

  8. Refactor logical worker synchronization code into a separate file.

  9. Standardize use of REFRESH PUBLICATION in code and messages.

  10. Add "ALL SEQUENCES" support to publications.

  11. Expose sequence page LSN via pg_get_sequence_data.

  12. Resume conflict-relevant data retention automatically.

  13. Post-commit review fixes for 228c370868.

  14. Generate GUC tables from .dat file

Attachments

Dear Vignesh,

Thanks for updating the patch. Below are my comments.

01.
```
		/* Relation is either a sequence or a table */
		relkind = get_rel_relkind(subrel->srrelid);
		if (relkind != RELKIND_SEQUENCE)
			continue;
```

Can you update the comment to "Skip if the relation is not a sequence"?
The current one seems not related with what we do.

02.
```
	appendStringInfo(&app_name, "%s_%s", MySubscription->name, "sequencesync worker");
```

I'm wondering what is the good application_name. One idea is to follow the
tablesync worker: "pg_%u_sequence_sync_%u_%llu", another one is to use the same
name as bgwoker: "logical replication sequencesync worker for subscription %u".
Your name is also valid but it looks quite different with other processes.
Do others have any opinions?

03.
```
test_pub=# SELECT NEXTVAL('s1');
```
I feel no need to be capital.

04.
```
   <link linkend="sql-createsubscription"><command>CREATE SUBSCRIPTION</command></link> or
   <link linkend="sql-altersubscription-params-refresh-publication">
   <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command></link> or
   <link linkend="sql-altersubscription-params-refresh-publication-sequences">
   <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION SEQUENCES</command></link>.
```

IIUC, we can use "A, B, or C" style.

05.
```
+        In logical replication, this parameter also limits how quickly a
+        failing replication apply worker or table synchronization worker or
+        sequence synchronization worker will be respawned.
```

Same as above.

06.
```
      <para>
       State codes for sequences:
       <literal>i</literal> = initialize,
       <literal>r</literal> = ready
      </para></entry>
```

Now the attribute can be "d".

07.

I feel we should add notes for subscription options. e.g., binary option
is no-op for sequence sync.

08.
```
	/* Get the list of tables and sequences from the publisher. */
	if (server_version >= 190000)
	{
```

Not sure which is better, but I considered a way to append the string atop v16.
Please see attached. How do you feel?

09.
fetch_relation_list() still has some "tables", which should be "relations".

10.
```
	if (sequencesync_worker)
	{
		/* Now safe to release the LWLock */
		LWLockRelease(LogicalRepWorkerLock);
		return;
	}
```

Not sure the comment is needed because the lock is acquired just above. Instead
we can describe that sequence sync worker exists up to one per a subscription.

11.
Currently copy_sequences() does not check privilege within the function, it is
done in SetSequence(). Basically it works well, but if the user does not have
enough privilege, for one of the sequence in the batch, ERROR would be
raised - all sequences cannot be synched. How about detecting it in the loop
and skip synchronizing? This allows other sequences to be synced.

12.
```
	/*
	 * This is a clean exit of the sequencesync worker; reset the
	 * last_seqsync_start_time.
	 */
	logicalrep_reset_seqsync_start_time();
```

ISTM the function can be used both sequence and table sync worker.

13.
```
		/* Fetch tables and sequences that are in non-ready state. */
		rstates = GetSubscriptionRelations(MySubscription->oid, true, true,
										   true);
```

IIUC no need to check sequences if has_pending_sequences is NULL.

Best regards,
Hayato Kuroda
FUJITSU LIMITED