You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve log messages and docs for slot synchronization.
Improve the clarity of LOG messages when a failover logical slot
synchronization fails, making the reasons more explicit for easier
debugging.
Update the documentation to outline scenarios where slot synchronization
can fail, especially during the initial sync, and emphasize that
pg_sync_replication_slot() is primarily intended for testing and
debugging purposes.
We also discussed improving the functionality of
pg_sync_replication_slot() so that it can be used reliably, but we would
take up that work for next version after some more discussion and review.
Reported-by: Suraj Kharage <suraj.kharage@enterprisedb.com>
Author: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 17, where it was introduced
Discussion: https://postgr.es/m/CAF1DzPWTcg+m+x+oVVB=y4q9=PYYsL_mujVp7uJr-_oUtWNGbA@mail.gmail.com
<varname>sync_replication_slots</varname></link> on the standby
376
+
is required. By enabling <link linkend="guc-sync-replication-slots">
377
377
<varname>sync_replication_slots</varname></link>
378
378
on the standby, the failover slots can be synchronized periodically in
379
379
the slotsync worker. For the synchronization to work, it is mandatory to
@@ -398,6 +398,52 @@ postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NU
398
398
receiving the WAL up to the latest flushed position on the primary server.
399
399
</para>
400
400
401
+
<note>
402
+
<para>
403
+
While enabling <link linkend="guc-sync-replication-slots">
404
+
<varname>sync_replication_slots</varname></link> allows for automatic
405
+
periodic synchronization of failover slots, they can also be manually
406
+
synchronized using the <link linkend="pg-sync-replication-slots">
407
+
<function>pg_sync_replication_slots</function></link> function on the standby.
408
+
However, this function is primarily intended for testing and debugging and
409
+
should be used with caution. Unlike automatic synchronization, it does not
410
+
include cyclic retries, making it more prone to synchronization failures,
411
+
particularly during initial sync scenarios where the required WAL files
412
+
or catalog rows for the slot may have already been removed or are at risk
413
+
of being removed on the standby. In contrast, automatic synchronization
414
+
via <varname>sync_replication_slots</varname> provides continuous slot
415
+
updates, enabling seamless failover and supporting high availability.
416
+
Therefore, it is the recommended method for synchronizing slots.
417
+
</para>
418
+
</note>
419
+
420
+
<para>
421
+
When slot synchronization is configured as recommended,
422
+
and the initial synchronization is performed either automatically or
423
+
manually via pg_sync_replication_slot, the standby can persist the
424
+
synchronized slot only if the following condition is met: The logical
425
+
replication slot on the primary must retain WALs and system catalog
426
+
rows that are still available on the standby. This ensures data
427
+
integrity and allows logical replication to continue smoothly after
428
+
promotion.
429
+
If the required WALs or catalog rows have already been purged from the
430
+
standby, the slot will not be persisted to avoid data loss. In such
431
+
cases, the following log message may appear:
432
+
<programlisting>
433
+
LOG: could not synchronize replication slot "failover_slot"
434
+
DETAIL: Synchronization could lead to data loss as the remote slot needs WAL at LSN 0/3003F28 and catalog xmin 754, but the standby has LSN 0/3003F28 and catalog xmin 756
435
+
</programlisting>
436
+
If the logical replication slot is actively used by a consumer, no
437
+
manual intervention is needed; the slot will advance automatically,
438
+
and synchronization will resume in the next cycle. However, if no
439
+
consumer is configured, it is advisable to manually advance the slot
440
+
on the primary using <link linkend="pg-logical-slot-get-changes">
441
+
<function>pg_logical_slot_get_changes</function></link> or
errmsg("could not synchronize replication slot \"%s\" because remote slot precedes local slot",
215
+
errmsg("could not synchronize replication slot \"%s\"",
216
216
remote_slot->name),
217
-
errdetail("The remote slot has LSN %X/%X and catalog xmin %u, but the local slot has LSN %X/%X and catalog xmin %u.",
217
+
errdetail("Synchronization could lead to data loss as the remote slot needs WAL at LSN %X/%X and catalog xmin %u, but the standby has LSN %X/%X and catalog xmin %u.",
218
218
LSN_FORMAT_ARGS(remote_slot->restart_lsn),
219
219
remote_slot->catalog_xmin,
220
220
LSN_FORMAT_ARGS(slot->data.restart_lsn),
@@ -577,7 +577,7 @@ update_and_persist_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid)
577
577
{
578
578
ereport(LOG,
579
579
errmsg("could not synchronize replication slot \"%s\"", remote_slot->name),
580
-
errdetail("Logical decoding could not find consistent point from local slot's LSN %X/%X.",
580
+
errdetail("Synchronization could lead to data loss as standby could not build a consistent snapshot to decode WALs at LSN %X/%X.",
0 commit comments