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.98.2) (envelope-from ) id 1xKHy5-00000000m9O-1Bre for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Oct 2026 16:18:09 +0000 Received: from localhost ([127.0.0.1]:39764 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xKHy4-0000000GWiy-2Guf for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Oct 2026 16:18:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:43048) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKHy4-0000000GWin-0ogt for pgsql-hackers@lists.postgresql.org; Fri, 23 Oct 2026 16:18:08 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKHy1-00000000bgP-495z for pgsql-hackers@postgresql.org; Fri, 23 Oct 2026 16:18:07 +0000 Received: from [0.0.0.0] (169.225.30.34.bc.googleusercontent.com [34.30.225.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4jB7Ts0GBRzySk; Fri, 23 Oct 2026 19:17:52 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1792772275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GVADSXy01aGNAnvN6JKynRx8svzh6glcxyJt3eU1Zvs=; b=FKeRnVDRAyehBstsmumvBon5byc47lZ7uckpstnRZAglC0Ih9ABVany2M91wlZ/Fic4KT5 lkCiiBXvKC7Rp4OwwLYHoW5bTi+JLpUUb+ZKPmPADyi0LCqRc3W7z8QHZsu5bEgv16jKD7 BVMnHV7rtXMMEicMihRkQ/ruiHDMARA= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1792772275; b=cUIZblZgaQDUYQIytAszfVh3L9aDqy85qw5+2VIdb/PodxDyU7OJ9O9NjBnX3RsPzjDo/n OZKyiNVz+X5suVjzX1vtXa1Bur2KfJOasVSpkNNA2dUDbxxQd+0FJcCpcqCHNvasL4uAl1 Z2+IJGrFNLDhTpil0wLJfTdQARoe+bI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1792772275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GVADSXy01aGNAnvN6JKynRx8svzh6glcxyJt3eU1Zvs=; b=oVNqPFk3V7ddK1jXcbWc0ptdBc0fl92z90VCJgeQjkN5y3t4b5x0qRXtdVZOOeVXWZFSjQ xo/Hx78u8n1cjmcX688ZD/eD1mAUbF7I22nCUy1RrCd6dNWp5HigfbrkAyjxmQHGv3lJ4s QscpoM/BqPvYuPbwikbza+TYHED9XbA= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <7971d005-e713-4a17-b0d9-855d9897ef14@iki.fi> Date: Fri, 23 Oct 2026 19:17:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Return pg_control from pg_backup_stop(). To: David Steele , Pg Hackers Cc: Michael Paquier , Robert Haas , Andres Freund , Fujii Masao , solai v References: <8b8aa673-fcef-4e14-a05d-0885283ef1b8@pgbackrest.org> <17DC1346-0CDE-4E39-B110-3D6FB0797AC6@gmail.com> <7F7B289B-F94F-42C2-9E54-6A689C0D64BB@gmail.com> <1800c83c-264a-4183-9da5-ac78e25849a8@pgbackrest.org> <3b23e3b7-53d2-4784-b482-05cca3327acb@pgbackrest.org> <4193dcbc-591e-44bb-816c-43b4ae70d31c@pgbackrest.org> <86436ff9-eb98-4c8a-825e-3bcae022107b@pgbackrest.org> <9b37265e-8025-4e8a-9a9c-c4232eaf746f@pgbackrest.org> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 23/10/2026 15:42, David Steele wrote: > Patch 02 implements the flag to enforce the presence of backup_label and > credits Andres with the original idea. This is the bulk of the prior patch. Makes sense at high level. > --- a/doc/src/sgml/backup.sgml > +++ b/doc/src/sgml/backup.sgml > @@ -1031,6 +1031,19 @@ SELECT * FROM pg_backup_stop(wait_for_archive => true); > vital to the backup working and must be written byte for byte without > modification, which may require opening the file in binary mode. > > + > + Note that a backup made with the low-level API copies > + pg_control from the running cluster, so it does not > + contain the flag that sets to make > + backup_label mandatory for recovery. Removing > + backup_label from such a backup will not prevent the > + cluster from starting; it will instead recover from the checkpoint > + recorded in pg_control. Unless that happens to be the > + checkpoint the backup started from, recovery will begin too late and > + silently produce an inconsistent cluster. > + Backup software using this API should set the flag itself if it is able to > + modify pg_control. > + > > > That's good advice, but the text feels awkward. Which flag do you need to set exactly? And maybe the text should be placed elsewhere; the copying of the pg_control file happened earlier already and you should probably modify it already when you copy it. > diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml > index b4a0faccf41..93676057394 100644 > --- a/doc/src/sgml/ref/pg_basebackup.sgml > +++ b/doc/src/sgml/ref/pg_basebackup.sgml > @@ -60,6 +60,18 @@ PostgreSQL documentation > must be used. > > > + > + The copy of pg_control stored in the backup is flagged > + to require the backup_label file for recovery. If > + backup_label is removed, recovery refuses to start > + rather than silently producing an inconsistent cluster. Restoring > + backup_label to the root of the backup allows > + recovery to proceed, and the flag is cleared once recovery has read the > + file. also clears the flag, but discarding > + the WAL bypasses the replay that recovery needs, leaving an inconsistent > + cluster. > + > + You shouldn't try to restore a backup_label file into an existing backup that's missing it, so that wording sounds dangerous. > > The backup is made over a regular PostgreSQL > connection that uses the replication protocol. The connection must be made > diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml > index ac3d0c9328f..c4888c183fb 100644 > --- a/doc/src/sgml/ref/pg_rewind.sgml > +++ b/doc/src/sgml/ref/pg_rewind.sgml > @@ -455,6 +455,10 @@ GRANT EXECUTE ON FUNCTION pg_catalog.pg_read_binary_file(text, bigint, bigint, b > defined as the result of pg_current_wal_insert_lsn() > when rewinding from a live source or the last checkpoint LSN when > rewinding from a stopped source. > + pg_control is also flagged to require > + backup_label, so that removing that file does not > + allow the target to start up in an inconsistent state. The flag is > + cleared once the target has processed backup_label. > > > That doesn't seem worth mentioning here; too much detail. > diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c > index 20be788da78..56368a9378f 100644 > --- a/src/backend/access/transam/xlogrecovery.c > +++ b/src/backend/access/transam/xlogrecovery.c > @@ -604,6 +604,10 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, > ereport(FATAL, > errmsg("could not find redo location %X/%08X referenced by checkpoint record at %X/%08X", > LSN_FORMAT_ARGS(checkPoint.redo), LSN_FORMAT_ARGS(CheckPointLoc)), > + ControlFile->backupLabelRequired ? > + errhint("Touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n" > + "Do not remove \"%s/backup_label\"; it is required to recover this backup.", > + DataDir, DataDir, DataDir) : > errhint("If you are restoring from a backup, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n" > "If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n" > "Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.", Umm, not new with his patch, but why do we still have that hint to remove backup_label? Is that ever the right thing to do? Why didn't we remove that hint when exclusive-mode backups were removed? Idea for further hardening: If you attempt to start up postgres and the backup_label is present, set the flag in the control file. That way, even if the backup tool doesn't modify the control file, it will be set on first startup attempt. If you delete the backup_label later, you still won't be able to start up into an inconsistent state. It won't protect you if you remove the backup_label before attempting to start up, but it'd catch some cases. - Heikki