From 8a28c255dd98c29fbdf60749d201a8e0010d507c Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Thu, 22 Dec 2022 02:49:48 +0000 Subject: [PATCH v2] Exit walsender before confirming remote flush in logical replication Currently, at shutdown, walsender processes wait to send all pending data and ensure the all data is flushed in remote node. This mechanism was added by 985bd7 for supporting clean switch over, but such use-case cannot be supported for logical replication. This commit remove the blocking in the case. Author: Hayato Kuroda --- src/backend/replication/walsender.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index c11bb3716f..7cc60a7dd1 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -3099,8 +3099,9 @@ XLogSendLogical(void) * NB: This should only be called when the shutdown signal has been received * from postmaster. * - * Note that if we determine that there's still more data to send, this - * function will return control to the caller. + * Note that if we determine that there's still more data to send or we are in + * physical replication mode and all WALs are not yet replicated, this function + * will return control to the caller. */ static void WalSndDone(WalSndSendDataCallback send_data) @@ -3118,8 +3119,17 @@ WalSndDone(WalSndSendDataCallback send_data) replicatedPtr = XLogRecPtrIsInvalid(MyWalSnd->flush) ? MyWalSnd->write : MyWalSnd->flush; - if (WalSndCaughtUp && sentPtr == replicatedPtr && - !pq_is_send_pending()) + /* + * Exit if we are in the convenient time. + * + * Note that in case of logical replication, we don't have to wait that all + * sent data to be flushed on the subscriber. It will request to send WALs + * from the last received point, and we cannot support clean switchover in + * logical replication. + */ + if (WalSndCaughtUp && + (send_data == XLogSendLogical || + (sentPtr == replicatedPtr && !pq_is_send_pending()))) { QueryCompletion qc; -- 2.27.0