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 1uJReA-0053xR-Gf for pgsql-hackers@arkaria.postgresql.org; Mon, 26 May 2025 06:49:18 +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 1uJRe9-003LYO-Ku for pgsql-hackers@arkaria.postgresql.org; Mon, 26 May 2025 06:49:17 +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.94.2) (envelope-from ) id 1uJRe9-003LYG-B7 for pgsql-hackers@lists.postgresql.org; Mon, 26 May 2025 06:49:16 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uJRe6-00090R-0A for pgsql-hackers@postgresql.org; Mon, 26 May 2025 06:49:16 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-b1ff9b276c2so910891a12.1 for ; Sun, 25 May 2025 23:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748242152; x=1748846952; 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=HR/k9fX2M2rqdB3iQERd+XdPIplokDOLV6u9onbKDTM=; b=PV1GGWRV7szHaOode3O29PEmjLeDyAmucOWJ5P6G1bdvZ1ffC9bacXixMTv/cayhpL D3qpCkj6HchE/K3ufB8v3RXzqyMcRkL3Mf2dwyVI7e5es4ycUfTRDOA1jNyMlGR2liob KxH/DWPNak4XHAGZZ8/j+DBWy0m4fkZ2Vyf7zKmGwSaAU+rkdIXRk8NIO4guBlTT4QMu QnQZEliL5M/eo4BQRcniA4HVIoiaAtG2+5/3RTW+Y4ghVOZ+LNR8ni2oGmMyZAC80nJc 9NQiceilrBD8p7jRapiDDvjP/LIVfhNpRI/Xux2zjM4kKUEc+nZCLyYBsHqQ0RdGcqST pBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748242152; x=1748846952; 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=HR/k9fX2M2rqdB3iQERd+XdPIplokDOLV6u9onbKDTM=; b=Irjez4nD+P9bRttsazN6KnXwYjcvarwwRMpPBh0zzBk/ugcIvYkaQlGG0d6kElAlD2 GEOC2sgZHwILtPEJm8fjJcski+qertjjz/LBFLBhtRZqStKE0u5ZfSvD3DKiFoEmie5w Uirh6FTeCpj/dYKTvNj3BrFCJCS9G2ubkDwEzgVxdt2wicCnnsCwKEQgzS+Y0D2YJ5yU 0qiUeN6xYs1iiMQuOjtSEN8mp6myu2LYqHbe5dems1OJV0rHZ8XrOEfSwoLU6RU/RCPQ eCyc0IkKiFrcO+hpeFhuJ046XKCkcRPwJ62HJi7cZdYkBzfPNZ+n/dFVisxiPnlQFkKy xuQA== X-Forwarded-Encrypted: i=1; AJvYcCWubS5kS8uY63Kt+Ol+tXGu3pD7BE7M7sajjrU+FVOmjKE1RF9YHWrVyIOdkVpYeWu+d5PvE21KKAkmBAEg@postgresql.org X-Gm-Message-State: AOJu0YxcYppxtrqE6ooMuS38veKtmSqKT7hpfZsGwWdTVxdhg7jHugKd 1biwuiCHGwAd4gnjxSrySHg9MNt4TY0GGXi4BO+cc+NCR+LsHCKStrrgyMp1FZZxD2c3HyNMDBS 1I7gmwwg4xiXnLRfhgPTW/VByP3cmHbSbmoHk X-Gm-Gg: ASbGnctkHDfnxXhsEVWXcVXrdHqQhFo1In0oMKOuG1Wnqi8OIQD4ONAKz+ntOYHNkbr 7SLBboqxZPje3CEO98fC/+clZouUJJaOEN5YqKXK1GPH75WfneK3lVzpWD3/06zMPG+oGTLR24l ZjLd+nmnEgqL9qC3kw3HfmpEJycYebeoTZMW4ittd6AIQB2w== X-Google-Smtp-Source: AGHT+IEdvLEaw6n05xfogIVhHsqbfMyf2RUsuRvl0ACZI9QnexuWrxUPu9Z9/WiXI08hv6BoAsoBP21uwtZ5nZAEGUE= X-Received: by 2002:a17:90b:1d51:b0:310:cf8f:6724 with SMTP id 98e67ed59e1d1-311106ac666mr12396797a91.30.1748242152050; Sun, 25 May 2025 23:49:12 -0700 (PDT) MIME-Version: 1.0 References: <1d12d2-67235980-35-19a406a0@63439497> <683f3c82-d38e-436d-88fd-27722af62005@vondra.me> <8679fea7-94ce-4a52-8e48-1a8cd0857fcb@vondra.me> <135e8-675c4600-21-304d7f40@228322535> <1538a2-67c5c700-7-77ec5a80@179382871> <27589a-680a4b80-6d-6e07880@117064404> <3ea6a1-68150580-1-7b53be0@80017081> <309f08-682ca380-25-139bf240@62751029> In-Reply-To: From: Amit Kapila Date: Mon, 26 May 2025 12:19:00 +0530 X-Gm-Features: AX0GCFtlgKKb2ttVo6_S9n6UQPj6GG6D6kYTAWsYPLvCmoJDndtcSs4Ysb11Fl4 Message-ID: Subject: Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly To: Alexander Korotkov Cc: Vitaly Davydov , 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 Sat, May 24, 2025 at 6:59=E2=80=AFPM Alexander Korotkov wrote: > > Hi, Amit! > > Thank you for your attention to this patchset! > > On Sat, May 24, 2025 at 2:15=E2=80=AFPM Amit Kapila wrote: > > On Sat, May 24, 2025 at 4:08=E2=80=AFPM Alexander Korotkov wrote: > > > > > > I spend more time on this. The next revision is attached. It > > > contains revised comments and other cosmetic changes. I'm going to > > > backpatch 0001 to all supported branches, > > > > > > > Is my understanding correct that we need 0001 because > > PhysicalConfirmReceivedLocation() doesn't save the slot to disk after > > changing the slot's restart_lsn? > > Yes. Also, even if it would save slot to the disk, there is still > race condition that concurrent checkpoint could use updated value from > the shared memory to clean old WAL segments, and then crash happens > before we managed to write the slot to the disk. > How can that happen, if we first write the updated value to disk and then update the shared memory as we do in LogicalConfirmReceivedLocation? BTW, won't there be a similar problem with physical slot's xmin computation as well? In PhysicalReplicationSlotNewXmin(), after updating the slot's xmin computation, we mark it as dirty and update shared memory values. Now, say after checkpointer writes these xmin values to disk, walsender receives another feedback message and updates the slot's xmin values. Now using these updated shared memory values, vacuum removes the rows, however, a restart will show the older xmin values in the slot, which mean vacuum would have removed the required rows before restart. As per my understanding, neither the xmin nor the LSN problem exists for logical slots. I am pointing this out to indicate we may need to think of a different solution for physical slots, if these are problems only for physical slots. --=20 With Regards, Amit Kapila.