Re: Logical Replication of sequences

shveta malik <shveta.malik@gmail.com>

From: shveta malik <shveta.malik@gmail.com>
To: vignesh C <vignesh21@gmail.com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, Nisha Moond <nisha.moond412@gmail.com>, Dilip Kumar <dilipbalaut@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>, Peter Smith <smithpb2250@gmail.com>, Masahiko Sawada <sawada.mshk@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>, shveta malik <shveta.malik@gmail.com>
Date: 2025-08-06T10:59:39Z
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

On Wed, Aug 6, 2025 at 2:28 PM vignesh C <vignesh21@gmail.com> wrote:
>
> The attached v20250806 version patch has the changes for the same.
>

Thank You for the patches. Please find a few comments:

1)
 * If 'resync_all_sequences' is false:
 *     Add or remove tables and sequences that have been added to or removed
 *         from the publication since the last subscription creation or refresh.
 * If 'resync_all_sequences' is true:
 *     Perform the above operation only for sequences.

Shall we update:
 Perform the above operation only for sequences and resync all the
sequences including existing ones.

2)
XLogRecPtr      srsublsn BKI_FORCE_NULL;        /* remote LSN of the
state change

Shall we rename it to srremotelsn or srremlsn? srsublsn gives a
feeling that it is local lsn and should be in sync with the one
displayed by pg_get_sequence_data() locally but that is not the case.

3)
create sequence myseq1 start 1 increment 100;
postgres=# select last_value, is_called, log_cnt, page_lsn  from
pg_get_sequence_data('myseq1');
 last_value | is_called | log_cnt |  page_lsn
------------+-----------+---------+------------
          1 | f         |       0 | 0/017BEF10

postgres=# select sequencename, last_value from pg_sequences;
 sequencename | last_value
--------------+------------
 myseq1       |

For a fresh sequence created, last_value shown by pg_get_sequence_data
seems wrong. On doging nextval for the first time, last_value shown by
pg_get_sequence_data does not change as the original value was wrong
itself to start with.

4)
+        Returns information about the sequence. <literal>last_value</literal>
+        is the current value of the sequence, <literal>is_called</literal>

It looks odd to say that 'last_value is the current value of the
sequence'. Why don't we name it curr_val? If this is an existing
function and thus we do not want to change the name, then we can say
something on the line that 'last sequence value set in sequence by
nextval or setval' or something
similar to what pg_sequences says for last_value.

5)
+        and <literal>page_lsn</literal> is the page LSN of the sequence
+        relation.

Is the page_lsn the page lsn of sequence relation or lsn of the last
WAL record written (or in simpler terms that particular record's
page_lsn)? If it is relation page-lsn, it should not change.

6)
I have noticed that when I do nextval, logcnt reduces and page_lsn is
not changed until it crosses the threshold. This is in context of
output returned by pg_get_sequence_data. But on doing setval, page_lsn
changes everytime and logcnt is reset to 0. Is this expected behaviour
or the issue in output of pg_get_sequence_data()? I did not get this
information from setval's doc. Can you please review and confirm?

postgres=# SELECT nextval('myseq2');
 nextval
---------
     155
postgres=#  select last_value, is_called, log_cnt, page_lsn  from
pg_get_sequence_data('myseq2');
 last_value | is_called | log_cnt |  page_lsn
------------+-----------+---------+------------
        155 | t         |      28 | 0/017C4498

postgres=# SELECT nextval('myseq2');
 nextval
---------
     175

postgres=#  select last_value, is_called, log_cnt, page_lsn  from
pg_get_sequence_data('myseq2');
 last_value | is_called | log_cnt |  page_lsn
------------+-----------+---------+------------
        175 | t         |      27 | 0/017C4498

postgres=# SELECT setval('myseq2', 55, true);
 setval
--------
     55

postgres=#  select last_value, is_called, log_cnt, page_lsn  from
pg_get_sequence_data('myseq2');
 last_value | is_called | log_cnt |  page_lsn
------------+-----------+---------+------------
         55 | t         |       0 | 0/017C4568

thanks
Shveta