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 1uSPSn-0076f5-9j for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jun 2025 00:18:37 +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 1uSPSl-00FaI8-0l for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jun 2025 00:18:35 +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 1uSPSk-00FaHk-NW for pgsql-hackers@lists.postgresql.org; Fri, 20 Jun 2025 00:18:35 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uSPSj-002yQT-1t for pgsql-hackers@postgresql.org; Fri, 20 Jun 2025 00:18:34 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-acb5ec407b1so212303666b.1 for ; Thu, 19 Jun 2025 17:18:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750378712; x=1750983512; 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=v+RyseQXP7DXRKsvvAEpKgbI2dwIoEeYINLChy5Tv84=; b=fZtbzMh/WtfURSlvImsBtk1/9CBTW2cIqY6bjovvClVoyrr8FUk14qtOpk+tRFcdaq K5UV8PjpyiizPA17wkXRr6gqxGT+fNP0pGYHH1nUCSGPSmtuoLiG9X5OSxTd6fjpe4zp WiUKUrqeLWrF1K3ut3wx93nRLGWhM/xtJrRvVqS8G4QKlPRRCtYLJZpRqRFA53vulcmO iL9XlwIUlkkOtGjHoMlHcmWi6UqMUfriM171vbbhv3CHAhqiZJcpe2MNw6Pmr4srbOqk z+gfqn1yYazuKbeL6+fGAT0+I4Jqqd+PDyz4cZyGFlG2mMA4t+gpvyZ3LL4zEJsTrznt x4fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750378712; x=1750983512; 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=v+RyseQXP7DXRKsvvAEpKgbI2dwIoEeYINLChy5Tv84=; b=Z0RNsEcqrTrHZJcWCr0ia0b/lknV8iuvTnltBxTe4/3LINcUcU1+mjWoDojvIF6Sr4 QO5Q4dMsXM6IkRhvSUSDjGvGOLut3DnUXpTWUIFDCRm7xEfjOi6KIhx5XckhphPCNfub f0GAF6afVtn01B+49+z2MHH3ni2tS7K/me/UETJicMqNcx+bSn/GSniw3zi4+jiB2DGI UxWUi0TLKhw0ZXv6WqZg9gw5qUwDwbSk9ylFC1mjZums03D5mSCB13qB79tPwiFOQrTv HBfRJ3uA1Fgu1tHuPgpyhaXMvgUQyiF3RSuMA9jtaQRuyZj2q9xI0irE/BPaas3wqZVn sWJQ== X-Forwarded-Encrypted: i=1; AJvYcCU8f7k8LZET9wErsU+lfQuaMC1dvH3IdZ1wrLFS3wSMhuygZ0fZbUPMQItehtNJDFg32D6qatE01aCq7WRZ@postgresql.org X-Gm-Message-State: AOJu0Yyd/hEhwxn03tOmoe55gJTs/eU20clvqYPOVlW49isiSKs9nhZL 8NdoXJ4F4rp/ep5jx/RmsLESffRwsLS1ogaeQ9o0VzRRJ6EY/h1f+UVFjNrt99cFPBVuhw24zwu Jq+HbLf/JPHaxN7drDU+vrtxG1+Kq4pY= X-Gm-Gg: ASbGncvOZzfnFHBiXhqHW54M5DhfIERm5teGMojhic7CSThBjIkOnBL3IQZQhDHTjlm H128NHObJ5QoAZTQFuYWs7SDHka488fuLLeUpMpf8Q7Dz5AJ1+7lsZQQdvL9vf3Wa0ah7tBUG41 JGsRQegGZcw/4sNDRA8wZ57fehDozlq5u6/wAyoR5Xpls= X-Google-Smtp-Source: AGHT+IGTRcbJNfcLfTQiMRvy9MeUAottHNZjdzzdpIm7Bl9YlSbQSdtbm3/kg1FJK5KGinTEC9z6KfeyZiQzopVFk/s= X-Received: by 2002:a17:907:3f08:b0:ade:4339:9358 with SMTP id a640c23a62f3a-ae0579d1feemr59294366b.22.1750378711649; Thu, 19 Jun 2025 17:18:31 -0700 (PDT) MIME-Version: 1.0 References: <1d12d2-67235980-35-19a406a0@63439497> <1d97ec-6841b600-3-b7b4780@40747246> <28c8bf-68470780-3-51b29480@89454035> <0a617d34-abc3-4090-92a5-ea15d45e36f6@gmail.com> <228607.1750003556@sss.pgh.pa.us> <3f242e-68518380-11-78125f00@134027639> <214ba-6852df80-9-7e0df800@134698799> <21b44-6852e000-3-a556820@87831171> In-Reply-To: From: Alexander Korotkov Date: Fri, 20 Jun 2025 03:18:20 +0300 X-Gm-Features: AX0GCFtuGmW9iVDRy6zMBbXB9xEz7Dk-Xs9Cn42NbKPSpr-HPaHKOgSkUNb9QGI Message-ID: Subject: Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly To: Amit Kapila Cc: Vitaly Davydov , vignesh C , "Hayato Kuroda (Fujitsu)" , Tom Lane , Alexander Lakhin , pgsql-hackers , Masahiko Sawada , "tomas@vondra.me" 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 Thu, Jun 19, 2025 at 1:29=E2=80=AFPM Amit Kapila wrote: > On Wed, Jun 18, 2025 at 10:17=E2=80=AFPM Alexander Korotkov > wrote: > > > > On Wed, Jun 18, 2025 at 6:50=E2=80=AFPM Vitaly Davydov wrote: > > > > I think, it is a good idea. Once we do not use the generated data, = it is ok > > > > just to generate WAL segments using the proposed function. I've tes= ted this > > > > function. The tests worked as expected with and without the fix. Th= e attached > > > > patch does the change. > > > > > > Sorry, forgot to attach the patch. It is created on the current maste= r branch. > > > It may conflict with your corrections. I hope, it could be useful. > > > > Thank you. I've integrated this into a patch to improve these tests. > > > > Regarding assertion failure, I've found that assert in > > PhysicalConfirmReceivedLocation() conflicts with restart_lsn > > previously set by ReplicationSlotReserveWal(). As I can see, > > ReplicationSlotReserveWal() just picks fresh XLogCtl->RedoRecPtr lsn. > > So, it doesn't seems there is a guarantee that restart_lsn never goes > > backward. The commit in ReplicationSlotReserveWal() even states there > > is a "chance that we have to retry". > > > > I don't see how this theory can lead to a restart_lsn of a slot going > backwards. The retry mentioned there is just a retry to reserve the > slot's position again if the required WAL is already removed. Such a > retry can only get the position later than the previous restart_lsn. Yes, if retry is needed, then the new position must be later for sure. What I mean is that ReplicationSlotReserveWal() can reserve something later than what standby is going to read (and correspondingly report with PhysicalConfirmReceivedLocation()). > > Thus, I propose to remove the > > assertion introduced by ca307d5cec90. > > > > If what I said above is correct, then the following part of the commit > message will be incorrect: > "As stated in the ReplicationSlotReserveWal() comment, this is not > always true. Additionally, this issue has been spotted by some > buildfarm > members." I agree, this comment needs improvement in terms of clarity. Meanwhile I've pushed the patch for TAP tests, which I think didn't get any objections. ------ Regards, Alexander Korotkov Supabase