postgresql/src/backend/replication/logical
Amit Kapila 3741f2a09d Fix the review comments and a bug in the slot sync code.
Ensure that when updating the catalog_xmin of the synced slots, it is
first written to disk before changing the in-memory value
(effective_catalog_xmin). This is to prevent a scenario where the
in-memory value change triggers a vacuum to remove catalog tuples before
the catalog_xmin is written to disk. In the event of a crash before the
catalog_xmin is persisted, we would not know that some required catalog
tuples have been removed and the synced slot would be invalidated.

Change the sanity check to ensure that remote_slot's confirmed_flush LSN
can't precede the local/synced slot during slot sync. Note that the
restart_lsn of the synced/local slot can be ahead of remote_slot. This can
happen when slot advancing machinery finds a running xacts record after
reaching the consistent state at a later point than the primary where it
serializes the snapshot and updates the restart_lsn.

Make the check to sync slots robust by allowing to sync only when the
confirmed_lsn, restart_lsn, or catalog_xmin of the remote slot is ahead of
the synced/local slot.

Reported-by: Amit Kapila and Shveta Malik
Author: Hou Zhijie, Shveta Malik
Reviewed-by: Amit Kapila, Bertrand Drouvot
Discussion: https://postgr.es/m/OS0PR01MB57162B67D3CB01B2756FBA6D94062@OS0PR01MB5716.jpnprd01.prod.outlook.com
Discussion: https://postgr.es/m/CAJpy0uCSS5zmdyUXhvw41HSdTbRqX1hbYqkOfHNj7qQ+2zn0AQ@mail.gmail.com
2024-04-12 15:10:41 +05:30
..
Makefile Add a slot synchronization function. 2024-02-14 09:45:36 +05:30
applyparallelworker.c Replace BackendIds with 0-based ProcNumbers 2024-03-03 19:38:22 +02:00
decode.c Merge prune, freeze and vacuum WAL record formats 2024-03-25 14:59:58 +02:00
launcher.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
logical.c Ensure that the sync slots reach a consistent state after promotion without losing data. 2024-04-03 14:04:59 +05:30
logicalfuncs.c Introduce a new GUC 'standby_slot_names'. 2024-03-08 08:10:45 +05:30
meson.build Add a slot synchronization function. 2024-02-14 09:45:36 +05:30
message.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
origin.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
proto.c Remove unused 'countincludesself' argument to pq_sendcountedtext() 2024-03-04 12:56:05 +02:00
relation.c Admit deferrable PKs into rd_pkindex, but flag them as such 2024-03-08 16:32:29 +01:00
reorderbuffer.c Revert indexed and enlargable binary heap implementation. 2024-04-11 17:18:05 +09:00
slotsync.c Fix the review comments and a bug in the slot sync code. 2024-04-12 15:10:41 +05:30
snapbuild.c Ensure that the sync slots reach a consistent state after promotion without losing data. 2024-04-03 14:04:59 +05:30
tablesync.c Fixup various StringInfo function usages 2024-04-10 11:53:32 +12:00
worker.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00