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 1t1nTd-000Qhr-7y for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Oct 2024 13:57:13 +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 1t1nTb-0050uG-Gi for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Oct 2024 13:57:11 +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 1t1nTb-0050u8-6d for pgsql-hackers@lists.postgresql.org; Fri, 18 Oct 2024 13:57:11 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t1nTX-001ilH-4t for pgsql-hackers@lists.postgresql.org; Fri, 18 Oct 2024 13:57:09 +0000 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2fb5fa911aaso34194491fa.2 for ; Fri, 18 Oct 2024 06:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729259826; x=1729864626; darn=lists.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=WqWjZi12AuqBsClzBkXYwgIqDMgPYs7omjy/PS+Avf8=; b=DSJoKxIDwuRaKvzYB9jwFI04avMtZBx7tUgCxPDWzBhOJC5hwnwQ12Hi2hRJ/x86GH tSoUQrwJwrOzXas0pFN1aV1BbsR7z+1klvhSd1EISSmxPb2SY9Wu7joKp3LD3IGGgMM9 tw9WZM0TbjMpBpxmPjwrTRCkr2jzHrLUV3eX/n57LLY6+lIwmV3aBmboxrAjqexBa29w MzgTKRU8lH9o87IR+zEvw2QcI29OSngpoNkLl2YtX81RhTgltEBy67fXJac7wbUYYdXy OePw+MAvwekfC0V+uVrJdjXdzNmIpkJ5QlX/Cn+pVNc171AR44I3Xq8c7w6nl8tRx1M7 htBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729259826; x=1729864626; 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=WqWjZi12AuqBsClzBkXYwgIqDMgPYs7omjy/PS+Avf8=; b=RSwYc3sUGUW7um/6UtSfkkbUAeShmyqMq2aKWoQK7BAdjdqhwzmlohyo9Og7fhFYAf qIMrbHg+IDv/WdQHp+wC5BO75fbEcTFG23Yj74C7wj1arGi2CQ3uc4trVl0HmWQM/pSf uTDyGd9bc7rurcOdmpNPkm8I/A33ViMVEL8qqP8C1YLst+APqzZE8UhxuQHgLhHNZjyZ MvR015lp91mm4JhShc1tphKqAe3I8lIcQRrN7BBrjYwSYniQEVho6lMenmJUA/Kgj8T4 /vofNCrrhvrKqFB6pje8Rm9ZUfHHW+55ZQHJYb0xswZehGTiD/dvYiN1M8w5cIy2l1sN fwdw== X-Gm-Message-State: AOJu0YzxMOpcrtVeP8wu9t2pHPyFLCPXi8gkUdA/wyHwhNSKvrviCrzr XfZehQMOscqFcsVLGH7bpHgdtansblBdHfmEOrurOl7a+ZRYsNLzIgXRbE7DjxfBg8fM10HmHEO xCzWqeSESapGB9ColJERQx72M0oU= X-Google-Smtp-Source: AGHT+IEOQNV32rw1HjqoKX4uAo4whbT2qAEHUYxIVbmswXLeZFCPYsXfio3CO0vdxoS8TjGnAt2ZlcCCorED809BDKo= X-Received: by 2002:a2e:8ecd:0:b0:2fb:4f8e:efd with SMTP id 38308e7fff4ca-2fb831ef969mr18159051fa.32.1729259825756; Fri, 18 Oct 2024 06:57:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Fri, 18 Oct 2024 15:56:53 +0200 Message-ID: Subject: Re: Recovery of .partial WAL segments To: Stefan Fercot Cc: "pgsql-hackers@lists.postgresql.org" 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, 5 Apr 2024 at 11:45, Stefan Fercot w= rote: > > Dear hackers, > > Generating a ".partial" WAL segment is pretty common nowadays (using pg_r= eceivewal or during standby promotion). > However, we currently don't do anything with it unless the user manually = removes that ".partial" extension. > > The 028_pitr_timelines tests are highlighting that fact: with test data b= eing being in 000000020000000000000003 and 000000010000000000000003.partial= , a recovery following the latest timeline (2) will succeed but fail if we = follow the current timeline (1). > > By simply trying to fetch the ".partial" file in XLogFileRead, we can eas= ily recover more data and also cover that (current timeline) recovery case. > > So, this proposed patch makes XLogFileRead try to restore ".partial" WAL = archives and adds a test to 028_pitr_timelines using current recovery_targe= t_timeline. Does this path only get hit when we don't already have any WAL segments (or partial segments) left for that timeline? I'm a bit worried about overwriting existing (partial) segments that may have more WAL than what we can get from archives. (patch v2) > + restoredArchivedFile =3D !RestoreArchivedFile(path, xlogfnam= e, > + "RECOVERYXLOG", > + wal_segment_size= , > + InRedo) && > + !RestoreArchivedFile(path, partialxlogfname, > "RECOVERYXLOG", > wal_segment_size, > - InRedo)) > + InRedo); The value of restoredArchiveFile is inverted with what it indicates: It is true when we failed to restore an archived xlog segment, and false if we did succeed. I'm also not a fan of the additional allocation of partialxlogfname in this code. It could well do without, by "just" reusing the xlogfname scratch space when we fail to recover the full segment. Kind regards, Matthias van de Meent Neon (https://neon.tech)