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.96) (envelope-from ) id 1wDHEj-002o0R-3A for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Apr 2026 07:34:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDHEj-004eE2-14 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Apr 2026 07:34:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wDHEj-004eDu-03 for pgsql-hackers@lists.postgresql.org; Thu, 16 Apr 2026 07:34:05 +0000 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wDHEg-00000001Mwp-2sT7 for pgsql-hackers@lists.postgresql.org; Thu, 16 Apr 2026 07:34:04 +0000 Received: by mail-ua1-x92e.google.com with SMTP id a1e0cc1a2514c-95695190911so1256280241.2 for ; Thu, 16 Apr 2026 00:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776324841; cv=none; d=google.com; s=arc-20240605; b=JnN0NBFw5Tyw2fKxL10IJfRjebf2xbSzLzmBxSz50s/831tgHvWXCW5AxIGlJ9oj95 yOP6lp09ZQZB9n7FfEP33N3CT5KKFP8rXbt1MxEIYjasYty8021Prm/DXSGEerH6iTCI GQld/yfFjH/9eVaI+GDHiLSKlfcgwIYoRTP51KJ3OCrqC7qxusdE67wRivj6YGrATW9y o5Rz8EH6LoySdZs5ZVK2ie6WuVaMzcSGzSYtFNWE6cDmsQ6PtJWgVywdTAw0cEDL+Beo OESL96rC11yrGvOk/xEwW/7XUgIiwoh0CJxlPBmDXU/H6WMHs5o8vv9sF/tObkwMkkEI iETQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=FZIgkO3sg1EsFJtLLMehWRqunN/EB5e22o/VQyTJfKI=; fh=muxfljgRAjvpJmqdFoRaqXG4b6EKysyhl06iX66+Y+4=; b=d1dTShawqzazFPceGRJrdBtOvrCVCvrOqUOGnBSeUnSzww2DFATV7pDw7Bl+Atfw4g vqUBdFyr03SH9n4hDizZ0GiQ2qFfN03F2cTywdUVkdKsZMKZqJszm2m9UgMhPXOwlc5v MSdYnqo/eP9411MYSIyPbFPlh5ZCJ77yh7LBdZjPLUEK1lufEj7WpT2nbABurGOpLNLR 8/DGmgok9FBSrwiAA66o3GNYVS610UioICAChUZs4/Go1h0FuGy988gycDiYPzKkKniM zytVWMx8PQpngz4Bm7eKoY9LYNCrtsvVbuTYV/K6jGuMIN3WL7RnmDB6VRqVjPyMCnYC HGpg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776324841; x=1776929641; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FZIgkO3sg1EsFJtLLMehWRqunN/EB5e22o/VQyTJfKI=; b=Ee7tlj1ir/m0avgAjKskYoyAvgGiviXs50lD8TGvQWmZMNClyV9LveWOmFechLwVDe 4MeLiZQ6H2AHPcXFamFNmtWrYEcwt3en5RcCHsjPxWbcXGEUHF3PWxzDl8e4HidkjAmv hV5Ww/6odVoMBs08rOLkvU1pxIt1ta+qOvf+Z28n3RvZ4Oqg5TNS7k61JMTsiBvPh9Pe V3JLFhq7RCE97xB/t8nAdEC55G9VoYle1cjz0TAQqtAC1YNnadHZE0mdsxSupwDARQGF VrFc3PBWc1GrQw5XZ6blSTDpPlML9gXIUz6kglrhY0FcX/PF+fMhuEUVXNBx/Y0eiWce vuxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776324841; x=1776929641; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FZIgkO3sg1EsFJtLLMehWRqunN/EB5e22o/VQyTJfKI=; b=k/SwHm/y/Mc2G5mqP5laW2LS5V8WGDX4+gX4Ui7akzA+oz4Lerxrz5M8FFwjWgAXP+ iUKNHSA1kzfTs9kKnpJ20x54W7bEg0DnPOH9WQi9SItHR356aX8cgMSS0JGbG4duUOrP 4p1Ls443zeWzDXOpNQ+J/Fuml34F4JacXQLzaS8uuLQwmsm0QOn5IJmVXYQK57qEI4fz U2PuJWaLU8xSL3ge8FO1XKlZqh3RVmHrb0tkE9Fu6lhS3058byin5g98cKONiJvTlBN+ tsHbcIDtc5ru8s/PV1qKipWxSktSnxzmc6W001QWUERmFpZyFafejeo3o+dEVNMrVb5R aTbw== X-Gm-Message-State: AOJu0YwhZHFQw/qGkCfpqg3UUJN1UmHY/5NMBywSXGcY6pbfMf/WTJW9 nATSDLuEHXVdbL15HGgnnXqwwRFz35zX/170/FL04y+LrXRVuyG5TkUGFGkqk+4p4Zh9FjxR0TB L8Q3upw0HyQ0VEZp+c1AjcgASPPcFGi0= X-Gm-Gg: AeBDieuDJQRBxY5Fbehksf94Bs96DUomkLx/u/Ega1syhB5PXKx5lXa/JMSFul3k5Ht H3UVvGww3YPyqBMWpLyGpUp6SR+JYNZhlDyXxV+WENQW7O6faXarshgs1ZQcN4jd02rSsCoJyS2 Ljnf+OTOIyI7lg2U4CDo/HMrzUTPXNPYTW+rPsDHlN3Ge7uRycPpBd8y9DztXP32u7ufReV6T4F igDH1E+I9AsbMopnbKvmjEG28Xa1xmtJa2ImL+39OQSZj3EwdThpRmOR020KR22ml05wiXHLHx1 u5+x7x7DfkS7qNGrbA== X-Received: by 2002:a05:6102:605a:b0:612:c135:1b77 with SMTP id ada2fe7eead31-612c1354555mr2330165137.27.1776324841039; Thu, 16 Apr 2026 00:34:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: SATYANARAYANA NARLAPURAM Date: Thu, 16 Apr 2026 00:33:47 -0700 X-Gm-Features: AQROBzBxxiDcP-VoT-21ZEYlBkghd_djxH3Xzj3DC-PiqvuQtLbLBUXTL5XpInQ Message-ID: Subject: Re: [PATCH] Fix WAIT FOR LSN standby_write/standby_flush for archive recovery cases To: Alexander Korotkov Cc: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="00000000000027ea3a064f8edbd4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000027ea3a064f8edbd4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Thu, Apr 16, 2026 at 12:31=E2=80=AFAM Alexander Korotkov wrote: > Hi, Satyanarayana! > > On Wed, Apr 15, 2026 at 9:44=E2=80=AFAM SATYANARAYANA NARLAPURAM > wrote: > > GetCurrentLSNForWaitType() for WAIT_LSN_TYPE_STANDBY_WRITE and > > WAIT_LSN_TYPE_STANDBY_FLUSH previously relied on the WAL receiver's > > tracked write/flush positions > (GetWalRcvWriteRecPtr/GetWalRcvFlushRecPtr). > > There are two scenarios where WAIT FOR LSN queries can be stalled thoug= h > > replay is making progress. Breaking it down to two to give clarity on > setups but > > the underlying problem is the same. > > > > There are two scenarios here: > > > > (1). When the standby is disconnected from the primary and switched to > WAL > > archive mode, it continues to be in that mode until no more WAL is > available to replay > > and then switch to streaming mode. Until then WAIT FOR LSN calls get > stuck on the > > standby though replay catches up beyond the stale WAL receiver position= . > Switching > > XLog source from archive to streaming is separately tracked in [1]. > > > > (2). In the case of Archive recovery, no WAL receiver process exists, s= o > these > > functions return InvalidXLogRecPtr (0/0). WAIT FOR LSN with > standby_flush or > > standby_write modes would always time out, even for WAL that has been > > fully replayed. > > > > Fix by falling back to the replay LSN (GetXLogReplayRecPtr) when the WA= L > > receiver position is invalid or behind replay. This is correct because > any > > WAL that has been replayed has necessarily already been written and > flushed > > to disk. Attached the repro test case. > > Please, check, similar patch is already posted here. > > > https://www.postgresql.org/message-id/CABPTF7Ukk8iJF7TpnK2mFOaboNJgWL1csf= Xu4e3J4GT0o7x0GQ%40mail.gmail.com Thanks, I will review it. --00000000000027ea3a064f8edbd4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Thu, Apr 16, = 2026 at 12:31=E2=80=AFAM Alexander Korotkov <aekorotkov@gmail.com> wrote:
Hi, Satyanarayana!

On Wed, Apr 15, 2026 at 9:44=E2=80=AFAM SATYANARAYANA NARLAPURAM
<satyanar= lapuram@gmail.com> wrote:
> GetCurrentLSNForWaitType() for WAIT_LSN_TYPE_STANDBY_WRITE and
> WAIT_LSN_TYPE_STANDBY_FLUSH previously relied on the WAL receiver'= s
> tracked write/flush positions (GetWalRcvWriteRecPtr/GetWalRcvFlushRecP= tr).
> There are two scenarios where WAIT FOR LSN queries can be stalled thou= gh
> replay is making progress. Breaking it down to two to give clarity on = setups but
> the underlying problem is the same.
>
> There are two scenarios here:
>
> (1). When the standby is disconnected from the primary and switched to= WAL
> archive mode, it continues to be in that mode until no more WAL is ava= ilable to replay
> and then switch to streaming mode. Until then WAIT FOR LSN calls get s= tuck on the
> standby though replay catches up beyond the stale WAL receiver positio= n. Switching
> XLog source from archive to streaming is separately tracked in [1]. >
> (2). In the case of Archive recovery, no WAL receiver process exists, = so these
> functions return InvalidXLogRecPtr (0/0). WAIT FOR LSN with standby_fl= ush or
> standby_write modes would always time out, even for WAL that has been<= br> > fully replayed.
>
> Fix by falling back to the replay LSN (GetXLogReplayRecPtr) when the W= AL
> receiver position is invalid or behind replay. This is correct because= any
> WAL that has been replayed has necessarily already been written and fl= ushed
> to disk. Attached the repro test case.

Please, check, similar patch is already posted here.

https://www.postgresql.org/message-id/CABPTF7Ukk8iJF7TpnK2mFOaboNJgWL= 1csfXu4e3J4GT0o7x0GQ%40mail.gmail.com

T= hanks, I will review it.
--00000000000027ea3a064f8edbd4--