pgsql: Fix pg_basebackup with in-place tablespaces some more.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix pg_basebackup with in-place tablespaces some more.
Date: 2023-04-18 15:35:22
Message-ID: E1ponMX-003hbM-Mh@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix pg_basebackup with in-place tablespaces some more.

Commit c6f2f01611d4f2c412e92eb7893f76fa590818e8 purported to make
this work, but problems remained. In a plain-format backup, the
files from an in-place tablespace got included in the tar file for
the main tablespace, which is wrong but it's not clear that it
has any user-visible consequences. In a tar-format backup, the
TABLESPACE_MAP option is used, and so we never iterated over
pg_tblspc and thus never backed up the in-place tablespaces
anywhere at all.

To fix this, reverse the changes in that commit, so that when we scan
pg_tblspc during a backup, we create tablespaceinfo objects even for
in-place tablespaces. We set the field that would normally contain the
absolute pathname to the relative path pg_tblspc/${TSOID}, and that's
good enough to make basebackup.c happy without any further changes.

However, pg_basebackup needs a couple of adjustments to make it work.
First, it needs to understand that a relative path for a tablespace
means it's an in-place tablespace. Second, it needs to tolerate the
situation where restoring the main tablespace tries to create
pg_tblspc or a subdirectory and finds that it already exists, because
we restore user-defined tablespaces before the main tablespace.

Since in-place tablespaces are only intended for use in development
and testing, no back-patch.

Patch by me, reviewed by Thomas Munro and Michael Paquier.

Discussion: http://postgr.es/m/CA+TgmobwvbEp+fLq2PykMYzizcvuNv0a7gPMJtxOTMOuuRLMHg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/363e8f9115469fe3d30a80b694cd60e9db3b2537

Modified Files
--------------
src/backend/access/transam/xlog.c | 110 ++++++++++++---------
src/bin/pg_basebackup/bbstreamer_file.c | 53 +++++++---
src/bin/pg_basebackup/pg_basebackup.c | 22 ++++-
src/bin/pg_basebackup/t/011_in_place_tablespace.pl | 40 ++++++++
4 files changed, 159 insertions(+), 66 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2023-04-18 17:32:00 pgsql: Fix Utils.pm's locale-munging so that Perl itself is also affect
Previous Message Michael Paquier 2023-04-18 03:03:45 pgsql: ecpg: Avoid C99-ism in newly-added test for Oracle compat