mirror of https://github.com/postgres/postgres
Commit c6f2f01611
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
pull/137/head
parent
f180290847
commit
363e8f9115
@ -0,0 +1,40 @@ |
||||
# Copyright (c) 2021-2023, PostgreSQL Global Development Group |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use PostgreSQL::Test::Cluster; |
||||
use PostgreSQL::Test::Utils; |
||||
use Test::More; |
||||
|
||||
my $tempdir = PostgreSQL::Test::Utils::tempdir; |
||||
|
||||
# For nearly all pg_basebackup invocations some options should be specified, |
||||
# to keep test times reasonable. Using @pg_basebackup_defs as the first |
||||
# element of the array passed to IPC::Run interpolate the array (as it is |
||||
# not a reference to an array)... |
||||
my @pg_basebackup_defs = ('pg_basebackup', '--no-sync', '-cfast'); |
||||
|
||||
# Set up an instance. |
||||
my $node = PostgreSQL::Test::Cluster->new('main'); |
||||
$node->init('allows_streaming' => 1); |
||||
$node->start(); |
||||
|
||||
# Create an in-place tablespace. |
||||
$node->safe_psql('postgres', <<EOM); |
||||
SET allow_in_place_tablespaces = on; |
||||
CREATE TABLESPACE inplace LOCATION ''; |
||||
EOM |
||||
|
||||
# Back it up. |
||||
my $backupdir = $tempdir . '/backup'; |
||||
$node->command_ok( |
||||
[ @pg_basebackup_defs, '-D', $backupdir, '-Ft', '-X', 'none' ], |
||||
'pg_basebackup runs'); |
||||
|
||||
# Make sure we got base.tar and one tablespace. |
||||
ok(-f "$backupdir/base.tar", 'backup tar was created'); |
||||
my @tblspc_tars = glob "$backupdir/[0-9]*.tar"; |
||||
is(scalar(@tblspc_tars), 1, 'one tablespace tar was created'); |
||||
|
||||
# All good. |
||||
done_testing(); |
Loading…
Reference in new issue