Re: Logical Replication of sequences
shveta malik <shveta.malik@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Doc: Add documentation for sequence synchronization.
- 55cefadde874 19 (unreleased) landed
-
Remove unused assignment in CREATE PUBLICATION grammar.
- bfb7419b0bbe 19 (unreleased) landed
-
Add seq_sync_error_count to subscription statistics.
- f6a4c498dcf6 19 (unreleased) landed
-
Fix few issues in commit 5509055d69.
- 5a4eba558aa7 19 (unreleased) landed
-
Add sequence synchronization for logical replication.
- 5509055d6956 19 (unreleased) landed
-
Add worker type argument to logical replication worker functions.
- 3e8e05596a02 19 (unreleased) landed
-
Introduce "REFRESH SEQUENCES" for subscriptions.
- f0b3573c3aac 19 (unreleased) landed
-
Refactor logical worker synchronization code into a separate file.
- 41c674d2e31e 19 (unreleased) landed
-
Standardize use of REFRESH PUBLICATION in code and messages.
- 2436b8c047ff 19 (unreleased) landed
-
Add "ALL SEQUENCES" support to publications.
- 96b378497346 19 (unreleased) landed
-
Expose sequence page LSN via pg_get_sequence_data.
- b93172ca59f4 19 (unreleased) landed
-
Resume conflict-relevant data retention automatically.
- 0d48d393d465 19 (unreleased) cited
-
Post-commit review fixes for 228c370868.
- 1f7e9ba3ac4e 19 (unreleased) cited
-
Generate GUC tables from .dat file
- 63599896545c 19 (unreleased) cited
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