Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyLvL-0002E7-3U for pgsql-hackers@arkaria.postgresql.org; Mon, 15 May 2023 00:18:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pyLvI-0006uU-Nb for pgsql-hackers@arkaria.postgresql.org; Mon, 15 May 2023 00:18:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyLvI-0006tf-AF for pgsql-hackers@lists.postgresql.org; Mon, 15 May 2023 00:18:44 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pyLvF-002MW0-9u for pgsql-hackers@postgresql.org; Mon, 15 May 2023 00:18:42 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 54E545C00A7; Sun, 14 May 2023 20:18:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 14 May 2023 20:18:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1684109919; x=1684196319; bh=9i QZH4ZEjtST+w1UZC/Rn6PwE/mKQEtSFRhvieqY6Uc=; b=TR/3TIsssp2jQy9YfL V4Rq6ruNYTIM2dW/Lv1qTT2YMmVhEH2Topl/5ir1XNI+NGgazdl+xromW4YvI7Yj L/c2LZG+EzIfIn75WIm1KzWJkhIM2aqC5t9q+Y2doBo8x8HGrOSAkJL0snAq1CAA ZNJaKFWhDIIwrkJonvuqrQWIBmMNaxCIDLEW43YZvey+HNw6LE+GLNWAGuEvW/hs Uam/H9WJgqryTLWRn4WXicry2HBlu8s0AlbKyU+KGR3IDjW5l91dqMuKvSbLCmim G5w9D7SOzt5WK1h8WKBOQPCHqAOJFBcfEkqnj2THuSyXo+GoINpJ8urnmyT2OT7j jW2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1684109919; x=1684196319; bh=9iQZH4ZEjtST+ w1UZC/Rn6PwE/mKQEtSFRhvieqY6Uc=; b=Knr4j2s69aR/pvGU1s2WCh0ejnOy/ NKQXui8+wJ6cyJ4W3aaKaXhgxxbKoqLJTHND0vWtGyCl8UyUkxG7qzONlrzCcA/A 8PQiE7m3ZAcW3ve62K0WA2Iub+AodrCb1SZcURq3Ubk5qqPuMarJzhCgntEmc3Ux dmrDcRFTbqmDb2aTxrXoKdrTGFg1j0PDpXbtaPDuTqNB9ZybkIoXWaMkp26Xy4Hu ZbtDfyka4BRP84NHcxG/ixg50b+POx1FY/rR5ElGPOKSbnYwyQyP5fsRys/+6bBh clkNEozqE1JPokSaZy3rolTpUEpn4fR0JTQmlI5A1FCJVi2PJuJ6/x2WQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehiedgfedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepledtveelffduteetgfetkefgtdfhhefggefhueffueettdetteekudfgudfguefh necuffhomhgrihhnpehsghhmlhdrhhhofienucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 14 May 2023 20:18:36 -0400 (EDT) Date: Mon, 15 May 2023 09:18:32 +0900 From: Michael Paquier To: torikoshia Cc: Bharath Rupireddy , Kyotaro Horiguchi , pgsql-hackers@postgresql.org Subject: Re: Allow pg_archivecleanup to remove backup history files Message-ID: References: <20230425.172948.1630351042955772893.horikyota.ntt@gmail.com> <5adce8cd5ad2269fe687d2d56a341c88@oss.nttdata.com> <61abc656edfba4a668b367d590b1aaab@oss.nttdata.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="khPDrvZN/9vBN01Y" Content-Disposition: inline In-Reply-To: <61abc656edfba4a668b367d590b1aaab@oss.nttdata.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --khPDrvZN/9vBN01Y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 12, 2023 at 05:53:45PM +0900, torikoshia wrote: > On 2023-05-10 17:52, Bharath Rupireddy wrote: > I was a little concerned about what to do when deleting both the files > ending in .gz and backup history files. > Is making it possible to specify both "-x .backup" and "-x .gz" the way to > go? >=20 > I also concerned someone might add ".backup" to WAL files, but does that > usually not happen? Depends on the archive command, of course. I have seen code using this suffix for some segment names in the past, FWIW. >> Comments on the patch: >> 1. Why just only the backup history files? Why not remove the timeline >> history files too? Is it because there may not be as many tli switches >> happening as backups? >=20 > Yeah, do you think we should also add logic for '-x .history'? Timeline history files can be critical pieces when it comes to assigning a TLI as these could be retrieved by a restore_command during recovery for a TLI jump or just assign a new TLI number at the end of recovery, still you could presumably remove the TLI history files that are older than the TLI the segment defined refers too. (pg_archivecleanup has no specific logic to look at the history with child TLIs for example, to keep it simple, and I'd rather keep it this way). There may be an argument for making that optional, of course, but it does not strike me as really necessary compared to the backup history files which are just around for debugging purposes. >> 2.+sub remove_backuphistoryfile_run_check >> +{ >> Why to invent a new function when run_check() can be made generic with >> few arguments passed? >=20 > Thanks, I'm going to reconsider it. + + Remove files including backup history files, whose suffix is .backup. + Note that when oldestkeptwalfile is a = backup history file, + specified file is kept and only preceding WAL files and backup hi= story files are removed. + This addition to the documentation looks unprecise to me. Backup history files have a more complex format than just the .backup suffix, and this is documented in backup.sgml. How about plugging in some long options, and use something more explicit like --clean-backup-history? - if ((IsXLogFileName(walfile) || IsPartialXLogFileName(walfile)) && + if (((IsXLogFileName(walfile) || IsPartialXLogFileName(walfile)) || + (removeBackupHistoryFile && IsBackupHistoryFileName(walfile))) = && strcmp(walfile + 8, exclusiveCleanupFileName + 8) < 0) Could it be a bit cleaner to split this check in two, saving one level of indentation on the way for its most inner loop? I would imagine something like: /* Check file name */ if (!IsXLogFileName(walfile) && !IsPartialXLogFileName(walfile)) continue; /* Check cutoff point */ if (strcmp(walfile + 8, exclusiveCleanupFileName + 8) >=3D 0) continue; //rest of the code doing the unlinks. -- Michael --khPDrvZN/9vBN01Y Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmRhelcACgkQnvQgOdby QH2SPRAAiDt0pXYzYGIT1EKRCqJUqPGcqNzTOm0sdNXaWOmZWEYYYlupGS1UobRt jA802uHh1okeivymt3owB1QJ+IQhgvHSGAo9GWtzA6AC6AbjSgyGxikoIIr8yT7o UTDIkwZKqRgT05dPPVZGt/2MFFNmM9UsaYVRB1QSC6MO/X3VCmpU1bTx+uJ5pLOd 4X3hjDyDIfBUxqkNRpzzMIT7mTeNJUTK3dx2Ngq3FYjR4G5BoOI9/4Ots+k4qzU4 10AlEK9DGAOxaxGCRkkYBxnmRvbROkB2+/GyabyAU+5kXFFWPUjb03Evl09Z2ndy MFyMNHZ6+TLt9mmfwaoWkGADOcl7Xfxc4bupZ2nfQltjqG3VhdsRoMyMq406Xclj EFtxpXOPWdb6jxbVTKmSR96BxcdWrlRBfkN/HI+KA/vCdyFS+9DNrHyfLNXKxCaP jSVuiMuP7JU+NrBkpBZ/vRaruWjuYaJlj7NLfGTIU0JW/yVRQtTiURRZvR2XvthS dRCxBIPoasbpzTj2yuj8/deFv0w657+v2WoxJVnaHHGMK8eUJNUFUceFypPq+mqp u+SmcXX/0YeTnVZrmScngVqR9QomVFPy1lwJYSmgogbPe3U+37aLu55HUHHyngy5 NBbecfQOmW1TPhS+o+gF/AJ9nBDN/o+c/HEaJPCWDC2IWUI/MoI= =LVjZ -----END PGP SIGNATURE----- --khPDrvZN/9vBN01Y--