pgsql: pg_combinebackup: Add -k, --link option.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_combinebackup: Add -k, --link option.
Date: 2025-03-17 18:09:30
Message-ID: E1tuEu2-002xw6-0z@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pg_combinebackup: Add -k, --link option.

This is similar to pg_upgrade's --link option, except that here we won't
typically be able to use it for every input file: sometimes we will need
to reconstruct a complete backup from blocks stored in different files.
However, when a whole file does need to be copied, we can use an
optimized copying strategy: see the existing --clone and
--copy-file-range options and the code to use CopyFile() on Windows.
This commit adds a new strategy: add a hard link to an existing file.
Making a hard link doesn't actually copy anything, but it makes sense
for the code to treat it as doing so.

This is useful when the input directories are merely staging directories
that will be removed once the restore is complete. In such cases, there
is no need to actually copy the data, and making a bunch of new hard
links can be very quick. However, it would be quite dangerous to use it
if the input directories might later be reused for any other purpose,
since starting postgres on the output directory would destructively
modify the input directories. For that reason, using this new option
causes pg_combinebackup to emit a warning about the danger involved.

Author: Israel Barth Rubio <barthisrael(at)gmail(dot)com>
Co-authored-by: Robert Haas <robertmhaas(at)gmail(dot)com> (cosmetic changes)
Reviewed-by: Vignesh C <vignesh21(at)gmail(dot)com>
Discussion: http://postgr.es/m/CA+TgmoaEFsYHsMefNaNkU=2SnMRufKE3eVJxvAaX=OWgcnPmPg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/99aeb84703177308c1541e2d11c09fdc59acb724

Modified Files
--------------
doc/src/sgml/ref/pg_combinebackup.sgml | 32 +++++-
src/bin/pg_combinebackup/copy_file.c | 33 +++++-
src/bin/pg_combinebackup/copy_file.h | 1 +
src/bin/pg_combinebackup/meson.build | 1 +
src/bin/pg_combinebackup/pg_combinebackup.c | 12 +-
src/bin/pg_combinebackup/t/010_hardlink.pl | 169 ++++++++++++++++++++++++++++
6 files changed, 245 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2025-03-17 18:16:22 pgsql: tests: Expand temp table tests to some pin related matters
Previous Message Robert Haas 2025-03-17 17:20:22 Re: pgsql: pg_upgrade: Preserve default char signedness value from old clus