Re: Synchronizing slots from primary to standby
Peter Smith <smithpb2250@gmail.com>
Here are some review comments for patch v80_2-0001. ====== Commit message 1. We may also see the the slots invalidated and dropped on the standby if the primary changes 'wal_level' to a level lower than logical. Changing the primary 'wal_level' to a level lower than logical is only possible if the logical slots are removed on the primary server, so it's expected to see the slots being removed on the standby too (and re-created if they are re-created on the primary server). ~ Typo /the the/the/ ====== src/sgml/logicaldecoding.sgml 2. + <para> + The logical replication slots on the primary can be synchronized to + the hot standby by enabling <literal>failover</literal> during slot + creation (e.g. using the <literal>failover</literal> parameter of + <link linkend="pg-create-logical-replication-slot"> + <function>pg_create_logical_replication_slot</function></link>, or + using the <link linkend="sql-createsubscription-params-with-failover"> + <literal>failover</literal></link> option of the CREATE SUBSCRIPTION + command), and then calling <link linkend="pg-sync-replication-slots"> + <function>pg_sync_replication_slots</function></link> + on the standby. For the synchronization to work, it is mandatory to + have a physical replication slot between the primary and the standby, and + <link linkend="guc-hot-standby-feedback"><varname>hot_standby_feedback</varname></link> + must be enabled on the standby. It is also necessary to specify a valid + <literal>dbname</literal> in the + <link linkend="guc-primary-conninfo"><varname>primary_conninfo</varname></link>. + </para> Shveta previously asked: Regarding link to create-sub, the 'sql-createsubscription-params-with-failover' takes you to the failover property of Create-Subscription page. Won't that suffice? PS: Yes, the current links in 80_2 are fine. ~ 2a. In hindsight, maybe it is simpler just to say "option of CREATE SUBSCRIPTION." instead of "option of the CREATE SUBSCRIPTION command." ~ 2b. Anyway, the "CREATE SUBSCRIPTION" should be rendered as a <command> ====== 3. +/* + * Flag to tell if we are syncing replication slots. Unlike the 'syncing' flag + * in SlotSyncCtxStruct, this flag is true only if the current process is + * performing slot synchronization. This flag is also used as safe-guard + * to clean-up shared 'syncing' flag of SlotSyncCtxStruct if some problem + * happens while we are in the process of synchronization. + */ 3a. It looks confusing to use the same word "process" to mean 2 different things. SUGGESTION This flag is also used as a safeguard to reset the shared 'syncing' flag of SlotSyncCtxStruct if some problem occurs while synchronizing. ~ 3b. TBH, I didn't think that 2nd sentence comment needed to be here -- it seemed more appropriate to say this comment inline where it does this logic in the function SyncReplicationSlots() ~~~ 4. local_sync_slot_required +/* + * Helper function to check if local_slot is required to be retained. + * + * Return false either if local_slot does not exist on the remote_slots list or + * is invalidated while the corresponding remote slot in the list is still + * valid, otherwise return true. + */ /does not exist on the remote_slots list/does not exist in the remote_slots list/ /while the corresponding remote slot in the list is still valid/while the corresponding remote slot is still valid/ ~~~ 5. + bool locally_invalidated = false; + bool remote_exists = false; + IMO it is more natural to declare these in the other order since the function logic assigns/tests them in the other order. ~~~ 6. + + if (!remote_exists || locally_invalidated) + return false; + + return true; IMO it would be both simpler and easier to understand if this was written as one line: return remote_exists && !locally_invalidated; ~~~ 7. + * Note: Change of 'wal_level' on the primary server to a level lower than + * logical may also result in slots invalidation and removal on standby. This + * is because such 'wal_level' change is only possible if the logical slots + * are removed on the primary server, so it's expected to see the slots being + * invalidated and removed on the standby too (and re-created if they are + * re-created on the primary). /may also result in slots invalidation/may also result in slot invalidation/ /removal on standby/removal on the standby/ ~~~ 8. + /* Drop the local slot f it is not required to be retained. */ + if (!local_sync_slot_required(local_slot, remote_slot_list)) I didn't think this comment was needed because IMO the function name is self-explanatory. Anyway, if you do want to keep it, then there is a typo to fix: /f it is/if it is/ ~~~ 9. + * Update the LSNs and persist the local synced slot for further syncs if the + * remote restart_lsn and catalog_xmin have caught up with the local ones, + * otherwise do nothing. Something about "persist ... for further syncs" wording seems awkward to me but I wasn't sure exactly what it should be. When I fed this comment into ChatGPT it interpreted "further" as "future" which seemed better. e.g. If the remote restart_lsn and catalog_xmin have caught up with the local ones, then update the LSNs and store the local synced slot for future synchronization; otherwise, do nothing. Maybe that is a better way to express this comment? ~~~ 10. +/* + * Validates if all necessary GUCs for slot synchronization are set + * appropriately, otherwise raise ERROR. + */ /Validates if all/Check all/ ====== Kind Regards, Peter Smith. Fujitsu Australia
Commits
-
Doc: Add the new section "Logical Replication Failover".
- b560a98a17ae 17.0 landed
-
Fix the review comments and a bug in the slot sync code.
- 3741f2a09d52 17.0 landed
-
Fix a test in failover slots regression test.
- 7e85d1c75f29 17.0 landed
-
Fix the intermittent buildfarm failures in 040_standby_failover_slots_sync.
- 6f3d8d5e7cc2 17.0 landed
-
Split XLogCtl->LogwrtResult into separate struct members
- c9920a9068ea 17.0 cited
-
Ensure that the sync slots reach a consistent state after promotion without losing data.
- 2ec005b4e297 17.0 landed
-
Introduce a new GUC 'standby_slot_names'.
- bf279ddd1c28 17.0 landed
-
Fix BF failure introduced by commit b3f6b14cf4.
- def0ce337068 17.0 landed
-
Fixups for commit 93db6cbda0.
- b3f6b14cf48f 17.0 landed
-
Fix BF failure in commit 93db6cbda0.
- d13ff82319cc 17.0 landed
-
Add a new slot sync worker to synchronize logical slots.
- 93db6cbda037 17.0 landed
-
Improve ERROR/LOG messages added by commits ddd5f4f54a and 7a424ece48.
- 801792e528d6 17.0 landed
-
Disable autovacuum on primary in 040_standby_failover_slots_sync test.
- b7bdade6a42f 17.0 landed
-
Fix the incorrect format specifier used in commit 7a424ece48.
- b987be39c3c7 17.0 landed
-
Change the LOG level in 040_standby_failover_slots_sync.pl to DEBUG2.
- d9e225f275b7 17.0 landed
-
Add more LOG and DEBUG messages for slot synchronization.
- 7a424ece4828 17.0 landed
-
Another try to fix BF failure introduced in commit ddd5f4f54a.
- 9bc1eee988c3 17.0 landed
-
Fix BF introduced in commit ddd5f4f54a.
- bd8fc1677b88 17.0 landed
-
Add a slot synchronization function.
- ddd5f4f54a02 17.0 landed
-
Clean-ups for 776621a5e4 and 7329240437.
- 22f7e61a6330 17.0 landed
-
Enhance libpqrcv APIs to support slot synchronization.
- dafbfed9efbe 17.0 landed
-
Add a failover option to subscriptions.
- 776621a5e479 17.0 landed
-
Allow setting failover property in the replication command.
- 73292404370c 17.0 landed
-
Allow to enable failover property for replication slots via SQL API.
- c393308b69d2 17.0 landed
-
Add macros for looping through a List without a ListCell.
- 14dd0f27d7cd 17.0 cited
-
Track conflict_reason in pg_replication_slots.
- 007693f2a3ac 17.0 cited
-
Allow upgrades to preserve the full subscription's state.
- 9a17be1e244a 17.0 cited
-
Add support for incremental backup.
- dc212340058b 17.0 cited
-
Simplify some logic in CreateReplicationSlot()
- e83aa9f92fdd 17.0 cited
-
Fix uninitialized access to InitialRunningXacts during decoding after ERROR.
- c7256e6564fa 15.5 cited
-
Flexible options for CREATE_REPLICATION_SLOT.
- 0266e98c6b86 15.0 cited
-
Empty search_path in logical replication apply worker and walsender.
- 11da97024abb 14.0 cited
-
Fix oldest xmin and LSN computation across repslots after advancing
- b48df818dcbd 14.0 cited
-
Require C99 (and thus MSCV 2013 upwards).
- d9dd406fe281 12.0 cited