Skip to content

Commit bf22792

Browse files
committed
Fix pg_rewind with in-place tablespaces when source is remote
libpq_source.c would consider any result returned by pg_tablespace_location() as a symlink, resulting in run-time errors like that: pg_rewind: error: file "pg_tblspc/NN" is of different type in source and target In-place tablespaces are directories located in pg_tblspc/, returned as relative paths instead of absolute paths, so rely on that to make the difference with a normal tablespace and an in-place one. If the path is relative, the tablespace is handled as a directory. If the path is absolute, consider it as a symlink. In-place tablespaces are only intended for development purposes, so like 363e8f9 no backpatch is done. A test is added in pg_rewind with an in-place tablespace and some data in it. Author: Rui Zhao, Michael Paquier Discussion: https://postgr.es/m/2b79d2a8-b2d5-4bd7-a15b-31e485100980.xiyuan.zr@alibaba-inc.com
1 parent b68e356 commit bf22792

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/bin/pg_rewind/libpq_source.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,16 @@ libpq_traverse_files(rewind_source *source, process_file_callback_t callback)
298298
link_target = PQgetvalue(res, i, 3);
299299

300300
if (link_target[0])
301-
type = FILE_TYPE_SYMLINK;
301+
{
302+
/*
303+
* In-place tablespaces are directories located in pg_tblspc/ with
304+
* relative paths.
305+
*/
306+
if (is_absolute_path(link_target))
307+
type = FILE_TYPE_SYMLINK;
308+
else
309+
type = FILE_TYPE_DIRECTORY;
310+
}
302311
else if (isdir)
303312
type = FILE_TYPE_DIRECTORY;
304313
else

src/bin/pg_rewind/t/001_basic.pl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ sub run_test
1818
RewindTest::setup_cluster($test_mode);
1919
RewindTest::start_primary();
2020

21+
# Create an in-place tablespace with some data on it.
22+
primary_psql("CREATE TABLESPACE space_test LOCATION ''");
23+
primary_psql("CREATE TABLE space_tbl (d text) TABLESPACE space_test");
24+
primary_psql(
25+
"INSERT INTO space_tbl VALUES ('in primary, before promotion')");
26+
2127
# Create a test table and insert a row in primary.
2228
primary_psql("CREATE TABLE tbl1 (d text)");
2329
primary_psql("INSERT INTO tbl1 VALUES ('in primary')");
@@ -78,6 +84,13 @@ sub run_test
7884
"insert into drop_tbl values ('in primary, after promotion')");
7985
primary_psql("DROP TABLE drop_tbl");
8086

87+
# Insert some data in the in-place tablespace for the old primary and
88+
# the standby.
89+
primary_psql(
90+
"INSERT INTO space_tbl VALUES ('in primary, after promotion')");
91+
standby_psql(
92+
"INSERT INTO space_tbl VALUES ('in standby, after promotion')");
93+
8194
# Before running pg_rewind, do a couple of extra tests with several
8295
# option combinations. As the code paths taken by those tests
8396
# do not change for the "local" and "remote" modes, just run them
@@ -145,6 +158,13 @@ sub run_test
145158

146159
RewindTest::run_pg_rewind($test_mode);
147160

161+
check_query(
162+
'SELECT * FROM space_tbl ORDER BY d',
163+
qq(in primary, before promotion
164+
in standby, after promotion
165+
),
166+
'table content');
167+
148168
check_query(
149169
'SELECT * FROM tbl1',
150170
qq(in primary

src/bin/pg_rewind/t/RewindTest.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ sub setup_cluster
131131
$node_primary->append_conf(
132132
'postgresql.conf', qq(
133133
wal_keep_size = 320MB
134+
allow_in_place_tablespaces = on
134135
));
135136
return;
136137
}

0 commit comments

Comments
 (0)