diff options
author | Amit Kapila <akapila@postgresql.org> | 2024-02-22 15:25:15 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2024-02-22 15:25:15 +0530 |
commit | 93db6cbda037f1be9544932bd9a785dabf3ff712 (patch) | |
tree | 804da2c1a7ee4634dc92789c98fa611dada365de /src/backend/access/transam/xlogrecovery.c | |
parent | 3d47b75546d1ef70145f58e162a96f7e0c649389 (diff) | |
download | postgresql-93db6cbda037f1be9544932bd9a785dabf3ff712.tar.gz postgresql-93db6cbda037f1be9544932bd9a785dabf3ff712.zip |
Add a new slot sync worker to synchronize logical slots.
By enabling slot synchronization, all the failover logical replication
slots on the primary (assuming configurations are appropriate) are
automatically created on the physical standbys and are synced
periodically. The slot sync worker on the standby server pings the primary
server at regular intervals to get the necessary failover logical slots
information and create/update the slots locally. The slots that no longer
require synchronization are automatically dropped by the worker.
The nap time of the worker is tuned according to the activity on the
primary. The slot sync worker waits for some time before the next
synchronization, with the duration varying based on whether any slots were
updated during the last cycle.
A new parameter sync_replication_slots enables or disables this new
process.
On promotion, the slot sync worker is shut down by the startup process to
drop any temporary slots acquired by the slot sync worker and to prevent
the worker from trying to fetch the failover slots.
A functionality to allow logical walsenders to wait for the physical will
be done in a subsequent commit.
Author: Shveta Malik, Hou Zhijie based on design inputs by Masahiko Sawada and Amit Kapila
Reviewed-by: Masahiko Sawada, Bertrand Drouvot, Peter Smith, Dilip Kumar, Ajin Cherian, Nisha Moond, Kuroda Hayato, Amit Kapila
Discussion: https://postgr.es/m/514f6f2f-6833-4539-39f1-96cd1e011f23@enterprisedb.com
Diffstat (limited to 'src/backend/access/transam/xlogrecovery.c')
-rw-r--r-- | src/backend/access/transam/xlogrecovery.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index 0bb472da278..d73a49b3e81 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -49,6 +49,7 @@ #include "postmaster/bgwriter.h" #include "postmaster/startup.h" #include "replication/slot.h" +#include "replication/slotsync.h" #include "replication/walreceiver.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1468,6 +1469,20 @@ FinishWalRecovery(void) XLogShutdownWalRcv(); /* + * Shutdown the slot sync worker to drop any temporary slots acquired by + * it and to prevent it from keep trying to fetch the failover slots. + * + * We do not update the 'synced' column from true to false here, as any + * failed update could leave 'synced' column false for some slots. This + * could cause issues during slot sync after restarting the server as a + * standby. While updating the 'synced' column after switching to the new + * timeline is an option, it does not simplify the handling for the + * 'synced' column. Therefore, we retain the 'synced' column as true after + * promotion as it may provide useful information about the slot origin. + */ + ShutDownSlotSync(); + + /* * We are now done reading the xlog from stream. Turn off streaming * recovery to force fetching the files (which would be required at end of * recovery, e.g., timeline history file) from archive or pg_wal. |