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 1sUoym-005uIZ-W0 for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2024 14:53:04 +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 1sUoyk-000Yr9-Ma for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2024 14:53:03 +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 1sUoyk-000Yr0-Cz for pgsql-hackers@lists.postgresql.org; Fri, 19 Jul 2024 14:53:02 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sUoyh-000O43-ON for pgsql-hackers@postgresql.org; Fri, 19 Jul 2024 14:53:01 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52ea952ce70so1857851e87.3 for ; Fri, 19 Jul 2024 07:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721400778; x=1722005578; 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=DZYmvpXn6nkQE2tHnuAyVtOTQ3tB9VzmD93CPGk+aqA=; b=ZJOklnOlQIgArTqAAbCPtXqMgFn6rYmDh8g0+/nfFmNOkp2lsn/prN/onSD/HY7sij uCMTQzk25ASkrQMHbN3r8dIG/fSBHXDRk4MWv6Zkwzd7+CMZrcbxRC4i5MsK/nXG+WRz if6+18ASlicMlsB7nMmFxeIEY/22LnZPcbMhGl3lFZ7KSTTAiq+9MJ5ERVO8EW1cPJ3e svt9Ojcd5KJ9niW5rbhtPycYOze5dUmVk4vzlU4/6e+2RP0WE8k4fa3qvlBXAlxmoQVm eXjQfVo/Oy14kZiur5/u0Gr2t0JbDrsMst7GLM1nN+7gra+hH54Lop5zHYb5pJPOZmHL PgBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721400778; x=1722005578; 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=DZYmvpXn6nkQE2tHnuAyVtOTQ3tB9VzmD93CPGk+aqA=; b=GZhWw7oThT8yGP35HtFb3fXh8M5tI2I7jT/1MxDKFMuM+xfYkbKVa1XXn7rigTCw0/ VRmEci2DcSo9LYMkdoEO9yqkmwJ3rcXqibiaAhYzVmCKb2RbaUvLChLmKY4PDG68PYSO +uihJISoTudJKS00LqKxCcGt67Jou6/WyYJPxIjfVIquZQk6XqfRL9CZPiy3Pi8csDB1 wxAfAFFNQCPZYuE6lf01lnv+QMKaqtCwNQV2XYkhlRwOYom1W6nZ/+UNpXHe4sCMj1c+ D63uaaiaeSA8KMANBLTDVhzj6FeNovc1LbS9s144oA6Dj+UR1RvLbB+9P0fQR6HuVHsh NKug== X-Gm-Message-State: AOJu0YzSk8PtJRgvje9CC3mPN0AbgWPesmkQtCmczdvMG2CggDEdycWB HZ9WE1nRmXwVgnVfvut+wWjpmOJxkViKJDOHT7nUYUkh6OfaVAXBp8u3DJ2H1egPlt6stybflV7 S/+8N67dUYHvTGadcG56gmK3kX2nGXy3C X-Google-Smtp-Source: AGHT+IEk0R61L8/NfDSzLOV14iaBCOumJKyWCLazKvlAk95bSYtYA4xjlEaGqZK155Yg9tIPgEu5lrOPWagJBPZGZs4= X-Received: by 2002:a05:6512:1292:b0:52c:c9b6:df0f with SMTP id 2adb3069b0e04-52ef588067amr1275284e87.61.1721400777469; Fri, 19 Jul 2024 07:52:57 -0700 (PDT) MIME-Version: 1.0 References: <04f4277e5ed4046773e46837110bed1381a2583f.camel@cybertec.at> <5468641ad821dad7aa3b2d65bf843146443a1b68.camel@cybertec.at> In-Reply-To: <5468641ad821dad7aa3b2d65bf843146443a1b68.camel@cybertec.at> From: Robert Haas Date: Fri, 19 Jul 2024 10:52:45 -0400 Message-ID: Subject: Re: Incremental backup from a streaming replication standby fails To: Laurenz Albe Cc: pgsql-hackers@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 Mon, Jul 15, 2024 at 11:27=E2=80=AFAM Laurenz Albe wrote: > On Sat, 2024-06-29 at 07:01 +0200, Laurenz Albe wrote: > > I played around with incremental backup yesterday and tried $subject > > > > The WAL summarizer is running on the standby server, but when I try > > to take an incremental backup, I get an error that I understand to mean > > that WAL summarizing hasn't caught up yet. > > > > I am not sure if that is working as designed, but if it is, I think it > > should be documented. > > I played with this some more. Here is the exact error message: > > ERROR: manifest requires WAL from final timeline 1 ending at 0/1967C260,= but this backup starts at 0/1967C190 > > By trial and error I found that when I run a CHECKPOINT on the primary, > taking an incremental backup on the standby works. > > I couldn't fathom the cause of that, but I think that that should either > be addressed or documented before v17 comes out. I had a feeling this was going to be confusing. I'm not sure what to do about it, but I'm open to suggestions. Suppose you take a full backup F; replay of that backup will begin with a checkpoint CF. Then you try to take an incremental backup I; replay will begin from a checkpoint CI. For the incremental backup to be valid, it must include all blocks modified after CF and before CI. But when the backup is taken on a standby, no new checkpoint is possible. Hence, CI will be the most recent restartpoint on the standby that has occurred before the backup starts. So, if F is taken on the primary and then I is immediately taken on the standby without the standby having done a new restartpoint, or if both F and I are taken on the standby and no restartpoint intervenes, then CF=3DCI. In that scenario, an incremental backup is pretty much pointless: every single incremental file would contain 0 blocks. You might as well just use the backup you already have, unless one of the non-relation files has changed. So, except in that unusual corner case, the fact that the backup fails isn't really costing you anything. In fact, there's a decent chance that it's saving you from taking a completely useless backup. On the primary, this doesn't occur, because there, each new backup triggers a new checkpoint, so you always have CI>CF. The error message is definitely confusing. The reason I'm not sure how to do better is that there is a large class of errors that a user could make that would trigger an error of this general type. I'm guessing that attempting a standby backup with CF=3DCI will turn out to be the most common one, but I don't think it'll be the only one that ever comes up. The code in PrepareForIncrementalBackup() focuses on what has gone wrong on a technical level rather than on what you probably did to create that situation. Indeed, the server doesn't really know what you did to create that situation. You could trigger the same error by taking a full backup on the primary and then try to take an incremental based on that full backup on a time-delayed standby (or a lagging standby) whose replay position was behind the primary, i.e. CI