[PATCH] Support automatic sequence replication
Ajin Cherian <itsajin@gmail.com>
From: Ajin Cherian <itsajin@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-02-03T03:48:25Z
Lists: pgsql-hackers
Attachments
- v2-0001-Support-automatic-sequence-replication.patch (application/octet-stream) patch v2-0001
Hello hackers, I'd like to propose an improvement to the sequence replication feature that was committed in [1]. The current implementation synchronizes sequences during initial subscription setup, but the sequence sync worker exits after this initial sync. This means that as sequences advance on the publisher, they drift from the subscriber values over time. Users must manually run ALTER SUBSCRIPTION ... REFRESH SEQUENCES to resynchronize, which requires monitoring and intervention. Proposed Enhancement: This patch changes the sequence sync worker to run continuously throughout the subscription lifetime, automatically detecting and correcting sequence drift. The key changes are: 1. The sequence sync worker remains running instead of exiting after initial sync, periodically checking for and synchronizing drifted sequences. 2. The worker uses an exponential backoff strategy - starting at 2 seconds, doubling up to a maximum of 30 seconds when sequences are in sync, and resetting to the minimum interval when drift is detected. 3. Since synchronization is now automatic, ALTER SUBSCRIPTION ... REFRESH SEQUENCES is no longer needed and has been removed. The patch modifies documentation to reflect the new behavior, removes the REFRESH SEQUENCES command from the grammar and subscription commands, and implements the continuous monitoring loop in sequencesync.c. Tap tests have been updated to verify automatic synchronization rather than manual refresh. The attached v2 patch is attached and ready for review. Thoughts and feedback are welcome! [1] - https://github.com/postgres/postgres/commit/5509055d6956745532e65ab218e15b99d87d66ce Best regards, Ajin Cherian Fujitsu Australia
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