Re: Logical Replication of sequences
vignesh C <vignesh21@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
Attachments
- v20250428-0003-Reorganize-tablesync-Code-and-Introduce-sy.patch (text/x-patch) patch v20250428-0003
- v20250428-0005-Documentation-for-sequence-synchronization.patch (text/x-patch) patch v20250428-0005
- v20250428-0004-Enhance-sequence-synchronization-during-su.patch (text/x-patch) patch v20250428-0004
- v20250428-0001-Introduce-pg_sequence_state-function-for-e.patch (text/x-patch) patch v20250428-0001
- v20250428-0002-Introduce-ALL-SEQUENCES-support-for-Postgr.patch (text/x-patch) patch v20250428-0002
On Sat, 26 Apr 2025 at 14:24, Peter Smith <smithpb2250@gmail.com> wrote:
>
> Hi Vignesh.
>
> Some review comments for v20250426-0005.
>
> 4b.
> AFAIK, when copy_data=false, then not only will *existing* sequences
> not be synchronised, but even the *new* sequences will not be
> synchronised. Effectively, when copy_data = false, then nothing at all
> happens for sequences as far as what the user sees, right?
>
> Experiment:
>
> test_pub=# create publication pub1 for all sequences;
> CREATE PUBLICATION
>
> test_sub=# create sequence s1;
> CREATE SEQUENCE
> NOTICE: created replication slot "sub1" on publisher
> CREATE SUBSCRIPTION
>
> test_pub=# create sequence s1;
> CREATE SEQUENCE
> test_pub=# select * from nextval('s1');
> nextval
> ---------
> 1
> (1 row)
>
> test_pub=# select * from nextval('s1');
> nextval
> ---------
> 2
> (1 row)
>
> test_pub=# select * from nextval('s1');
> nextval
> ---------
> 3
> (1 row)
>
> test_sub=# alter subscription sub1 refresh publication with (copy_data=false);
> ALTER SUBSCRIPTION
>
> test_sub=# select * from s1;
> last_value | log_cnt | is_called
> ------------+---------+-----------
> 1 | 0 | f
> (1 row)
>
> So, subscriber side s1 is unaffected.
>
> Maybe it is not worth the effort, but doesn't this mean that you could
> optimise the AlterSubscription_refresh() logic to completely skip all
> processing for sequences when copy_data=false. e.g. what's the point
> of gathering publisher sequence lists and setting INIT states for
> them, etc, when it won't synchronise anything because copy_data=false?
> Everything will be synchronised later anyway when the user does
> REFRESH PUBLICATION SEQUENCES.
Currently this is in line with table behavior, I felt let's keep it
that way so that it will be easier to extend sequence replication as
use cases grow and will become more in sync with tables.
The rest of the comments were fixed, the attached v20250428 version
patch has the changes for the same.
Also the issue reported at [1] is available in the attached patch.
[1] - https://www.postgresql.org/message-id/CAHut%2BPujY8Xd%3DT94zuPuF21s0dLRGVJaXgRnLbGE47pwSpo-YA%40mail.gmail.com
Regards,
Vignesh