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 1tfPnZ-002GMw-35 for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Feb 2025 20:45:33 +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 1tfPnW-008REa-43 for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Feb 2025 20:45:30 +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 1tfPnV-008RER-QM for pgsql-hackers@lists.postgresql.org; Tue, 04 Feb 2025 20:45:29 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tfPnT-003Bh4-0Y for pgsql-hackers@lists.postgresql.org; Tue, 04 Feb 2025 20:45:28 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-ab6fb2940d4so30267166b.1 for ; Tue, 04 Feb 2025 12:45:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738701925; x=1739306725; 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=xLk9GUjcpLF00ZzmroWZDOlQJFOcXvITFaC9rvvW0bM=; b=bWFlFuEUoN0GX4heJ7KXQWdmpwUZiCYlTHKYLY6uGB100JUtxTdlRYBrdi7OngrpZg wfRQoQkTJGFEpCy0Kt07Kd8EAZd2JX4gb2Jc49XDJ5hAVk+3yebVe0y+m8mvdAaVi9Zn bz3lTAqhvtXzlj87nxXTDO1NfYcWIk6F6J4zAGaMVEup4zJ9vSbgcc23XfSnnpb8KI3Q +/dm599VityT9xzOIJjdxSN+9I7vWtI6lWlZxcFA/P6pGrIPHbuyzpLTnK3zV/nAAyX0 OLsl/dNjp9kYY124RvrSVyYtNpVpdJML1FY0xqP/+gZotTbFXzEc7BEdO5dEsgJi63pY Zohw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738701925; x=1739306725; 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=xLk9GUjcpLF00ZzmroWZDOlQJFOcXvITFaC9rvvW0bM=; b=jrVRC+j45OuxF/tv6DO7IS7FyNuEdZFkK6xNGUR3FCDiUgnodUpoQfNHAh/hL55rnF zEJyfSL0Npq3yLuyUP16ifzolbDG489fOqDVbTqDT3w8rnnneNUtyOGCsvcW8D2iJ+xo yCiWqiOmsLg+My62iSolTtFbSEFi2v4hi/Va7lXY0s7OyT6Vjt8rCzX8ugVDeM/9AT8D BCZtzpG7xpoeFihIEEtstpMU+KANaPz6gJW2c/mpzIj53WixIjAou2g7FVVJrp4fM4Ve 7waQnrEzEXaP69AskhodpTxiCrdCCQIUOuk8xkepFJJ88aIfCQ8glRzGFN/VQhR5guvi PJaQ== X-Gm-Message-State: AOJu0YykmvVE5EqlM50bjzzKplz4TB4RcVBs1jntu1Lb9fbekyL+hN7W 8JGrITHlKey78ukc0A5qBLaV0XKZQmKgMA9/udNjjh+lVvP21K+SwbJM4yKGZtFvDlJd3W5LrW5 0Huu/97goSycD4zfMvB/DIunW82Q= X-Gm-Gg: ASbGncswJmolkrKuVzVDINRoypTUdeqip2rvAo2qag6rUNmfNXXuORmqWmqm9i5Y5SJ Z4x6CM1i+MRK3QqBO6Z2z+B5xhuGJEgCkPOAEnZEVLk1FgQAovlQubfHlIYzq81gyvNnAJe/G X-Google-Smtp-Source: AGHT+IFkvTK5ICEDYvJmPjLoqQL1YjQjaSC0JktLBJGBg9fv7uVF2sLNMfsh+CLo/9wZlZiromfxGHuyCJYj9gYHY4w= X-Received: by 2002:a17:907:720e:b0:ab2:c0b0:3109 with SMTP id a640c23a62f3a-ab7484ef4a6mr547591666b.21.1738701924901; Tue, 04 Feb 2025 12:45:24 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Tue, 4 Feb 2025 15:45:13 -0500 X-Gm-Features: AWEUYZkg8tilUlCwM-kDV5Z2ZzI6mEVozhRRVw482GV9Dgu-Li8tU81TJzycz3c Message-ID: Subject: Re: Add -k/--link option to pg_combinebackup To: Israel Barth Rubio Cc: PostgreSQL Hackers 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 Wed, Jan 15, 2025 at 12:42=E2=80=AFPM Israel Barth Rubio wrote: > With the current implementation of pg_combinebackup, we have a few > copy methods: --clone, --copy and --copy-file-range. By using either of > them, it implicates an actual file copy in the file system, i.e. among > other things, disk usage. > > While discussing with some people, e.g. Robert Haas and Mart=C3=ADn Marqu= =C3=A9s, > about possible ways to improve pg_combinebackup performance and/or > reduce disk usage taken by the synthetic backup, there was a thought > of using hard links. > > I'm submitting a patch in this thread which introduces the -k/--link > option to pg_combinebackup, making it similar to the options exposed > by pg_upgrade. In general, +1, although I think that the patch needs polishing in a bunch of areas. Originally, I thought what we wanted was something like a --in-place option to pg_combinebackup, allowing the output directory to be the same as one of the input directories. However, I now think that what this patch does is likely better, and this patch is a lot simpler to write than that one would be. With the --in-place option, if I'm combine backup1 and backup2, I must write either "pg_combinebackup backup1 backup2 -o backup1" or "pg_combinebackup backup1 backup2 -o backup2". In either case, I can skip whole-file copies from one of the two source directories -- whichever one happens to be the output directory. However, if I write "pg_combinebackup --link backup1 backup2 -o result", I can skip *all* whole-file copies from *every* input directory, which seems a lot nicer. Furthermore, if all the input directories are staging directories, basically copies of original backups stored elsewhere, then the fact that those directories get trashed is of no concern to me. In fact, they don't even get trashed if pg_combinebackup is interrupted partway through, because I can just remove the output directory and recreate it and everything is fine. With an --in-place option, that would be trickier. Regarding the patch itself, I think we need to rethink the test case changes in particular. As written, the patch won't do any testing of link mode unless the user sets PG_TEST_PG_COMBINEBACKUP_MODE=3D--link; and if they do set that option, then we won't test anything else. Also, even with that environment variable set, we'll only test --link mode a bit ... accidentally. The patch doesn't really do anything to make sure that link mode actually does what it's intended to do. It only adapts the existing tests not to fail. I think it would be better to decide that you're not supposed to set PG_TEST_PG_COMBINEBACKUP_MODE=3D--link, and then write some new test, not depending on PG_TEST_PG_COMBINEBACKUP_MODE, that specifically verifies that link mode behaves as expected. After all, link mode is noticeably different from the other copy modes. Those should all produce equivalent results, or fail outright, we suppose. This produces a different user-visible result, so we probably ought to test that we get that result. For example, we might check that certain files end up with a link count of 1 or 2, as appropriate. Does link() work on Windows? I'm not sure what to do about the issue that using --link trashes the input cluster if you subsequently start the database or otherwise modify any hard-linked files. Keep in mind that, for command-line arguments other than the first, these are incremental backups, and you already can't run postgres on those directories. Only the first input directory, which is a full backup not an incremental, is a potential target for an unexpected database start. I'm tentatively inclined to think we shouldn't modify the input directories and just emit a warning like: warning: --link mode was used; any modifications to the output directory may destructively modify input directories ...but maybe that's not the right idea. Happy to hear other opinions. --=20 Robert Haas EDB: http://www.enterprisedb.com