Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQm4J-003Un7-CN for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jan 2024 10:25:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rQm4H-008eGi-9n for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jan 2024 10:25:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQm4H-008eGZ-0W for pgsql-hackers@lists.postgresql.org; Fri, 19 Jan 2024 10:25:45 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rQm49-002Imq-TO for pgsql-hackers@postgresql.org; Fri, 19 Jan 2024 10:25:43 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-337bad75860so401797f8f.1 for ; Fri, 19 Jan 2024 02:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705659936; x=1706264736; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ka9djmu6eGbEnlVaeUz6CJ5oJs6QT8MCZ1R00mBWceI=; b=X3+AfAKhd3hi2+YaCrI9glPRjKNHzMuZ0yJawhXbP0mHtkIM6lw1Nw8eT07I0U9IEW L6JntnYMlBTviZ+yLSecDy+50argm2C9UJvEKp8jypjnv95qektmi95DZUA0K+4Zg+5Z s21hKm1eC58L+/MGCw+AwQXo8CWGUNXrMPDN+XsmbuuA3ftA5/Ge1sX6dugktGO6hREZ R1mMbkzrp851cTY3L95FiJt+qTcogF9tYkS65OI9rEAP4qSDVKxj/OEC3YHLNsz67J3s 0LJ0Wo7ftj+S9aM1gv/lDoGcRDVQ9Na+l5CKJFZeur9ZCDAlqNjI+kZL+kB7QrKcrCy7 EClA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705659936; x=1706264736; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ka9djmu6eGbEnlVaeUz6CJ5oJs6QT8MCZ1R00mBWceI=; b=PKmIErDPgaq7BZWtnW5anZTR9YCjFgEVw5mB4RRHr25/n+7nBcuuxGGwdPjdspsTcm 89E+7GrBxpLb32valWNCEbpkmrSEx8o+9gEqTYPRBAZWN+9DcPCvVB8uIowSFVJfbq7b e3AWtXddC/bEgNHETbwMs3P67rVAXedfRG9PToWFoQz5Ciw8/OFnRjekuN7+T0SNXtUP Ge+YDSqYvrlb9+eKy8fiV8EAMSf7vJi6hik95FenKKbmjbJRJO+5a/HEqbeQxwOHLy2a lF9OOQadhzw3L97fy8Gyk2ov53koxGXQCUnik1Vfd4wm+viLu0LTRTNa7TNOLsXwboMp qZGg== X-Gm-Message-State: AOJu0YzTg9JFJRVtr3493Pk3WtKnU/vQZPRTf+ahdnyp52Jsj1UVR1/I ZmT92QDC4OS0H8D1aotlZmKhnoMPuj2qmYWvJXfIHWsmf078FsRsb+tWx0y8h22daafIPNiqNTP S27Yzg1clszWv32Q2h05SInHLYQs= X-Google-Smtp-Source: AGHT+IEngeGliBYZfIR5FOVUl9hAenMGVAulW9e8CyHSSkZ0uwOmSw8t84Gp1q+6avPlxd1hZD/kby0Gh4MEDU7Nf00= X-Received: by 2002:adf:f152:0:b0:337:8bc6:dce with SMTP id y18-20020adff152000000b003378bc60dcemr1377277wro.58.1705659936128; Fri, 19 Jan 2024 02:25:36 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Fri, 19 Jan 2024 15:55:24 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: Masahiko Sawada Cc: Bertrand Drouvot , Amit Kapila , "Zhijie Hou (Fujitsu)" , Dilip Kumar , Peter Smith , Nisha Moond , "Hayato Kuroda (Fujitsu)" , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , Ajin Cherian , Alvaro Herrera , shveta malik Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jan 19, 2024 at 10:35=E2=80=AFAM Masahiko Sawada wrote: > > > Thank you for updating the patch. I have some comments: > > --- > + latestWalEnd =3D GetWalRcvLatestWalEnd(); > + if (remote_slot->confirmed_lsn > latestWalEnd) > + { > + elog(ERROR, "exiting from slot synchronization as the > received slot sync" > + " LSN %X/%X for slot \"%s\" is ahead of the > standby position %X/%X", > + LSN_FORMAT_ARGS(remote_slot->confirmed_lsn), > + remote_slot->name, > + LSN_FORMAT_ARGS(latestWalEnd)); > + } > > IIUC GetWalRcvLatestWalEnd () returns walrcv->latestWalEnd, which is > typically the primary server's flush position and doesn't mean the LSN > where the walreceiver received/flushed up to. yes. I think it makes more sense to use something which actually tells flushed-position. I gave it a try by replacing GetWalRcvLatestWalEnd() with GetWalRcvFlushRecPtr() but I see a problem here. Lets say I have enabled the slot-sync feature in a running standby, in that case we are all good (flushedUpto is the same as actual flush-position indicated by LogstreamResult.Flush). But if I restart standby, then I observed that the startup process sets flushedUpto to some value 'x' (see [1]) while when the wal-receiver starts, it sets 'LogstreamResult.Flush' to another value (see [2]) which is always greater than 'x'. And we do not update flushedUpto with the 'LogstreamResult.Flush' value in walreceiver until we actually do an operation on primary. Performing a data change on primary sends WALs to standby which then hits XLogWalRcvFlush() and updates flushedUpto same as LogstreamResult.Flush. Until then we have a situation where slots received on standby are ahead of flushedUpto and thus slotsync worker keeps one erroring out. I am yet to find out why flushedUpto is set to a lower value than 'LogstreamResult.Flush' at the start of standby. Or maybe am I using the wrong function GetWalRcvFlushRecPtr() and should be using something else instead? [1]: Startup process sets 'flushedUpto' here: ReadPageInternal-->XLogPageRead-->WaitForWALToBecomeAvailable-->RequestXLog= Streaming [2]: Walreceiver sets 'LogstreamResult.Flush' here but do not update 'flushedUpto' here: WalReceiverMain(): LogstreamResult.Write =3D LogstreamResult.Flush =3D GetXLogReplayRecPtr(NULL) > Does it really happen > that the slot's confirmed_flush_lsn is higher than the primary's flush > lsn? It may happen if we have not configured standby_slot_names on primary. In such a case, slots may get updated w/o confirming that standby has taken the change and thus slot-sync worker may fetch the slots which have lsns ahead of the latest WAL position on standby. thanks Shveta