diff options
author | Michael Paquier <michael@paquier.xyz> | 2023-07-30 15:26:25 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2023-07-30 15:26:25 +0900 |
commit | bf227926d22b5cffba4b6724df0eb239a7037cbd (patch) | |
tree | ce46264b70e75181eb1fbde58a91615215677217 /src | |
parent | b68e356a680ee1155b0dc612a89655e98320121a (diff) | |
download | postgresql-bf227926d22b5cffba4b6724df0eb239a7037cbd.tar.gz postgresql-bf227926d22b5cffba4b6724df0eb239a7037cbd.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_rewind/libpq_source.c | 11 | ||||
-rw-r--r-- | src/bin/pg_rewind/t/001_basic.pl | 20 | ||||
-rw-r--r-- | src/bin/pg_rewind/t/RewindTest.pm | 1 |
3 files changed, 31 insertions, 1 deletions
diff --git a/src/bin/pg_rewind/libpq_source.c b/src/bin/pg_rewind/libpq_source.c index 0d8e9ee2d1a..417c74cfefc 100644 --- a/src/bin/pg_rewind/libpq_source.c +++ b/src/bin/pg_rewind/libpq_source.c @@ -298,7 +298,16 @@ libpq_traverse_files(rewind_source *source, process_file_callback_t callback) link_target = PQgetvalue(res, i, 3); if (link_target[0]) - type = FILE_TYPE_SYMLINK; + { + /* + * In-place tablespaces are directories located in pg_tblspc/ with + * relative paths. + */ + if (is_absolute_path(link_target)) + type = FILE_TYPE_SYMLINK; + else + type = FILE_TYPE_DIRECTORY; + } else if (isdir) type = FILE_TYPE_DIRECTORY; else diff --git a/src/bin/pg_rewind/t/001_basic.pl b/src/bin/pg_rewind/t/001_basic.pl index 031594e14e6..c7b48255a71 100644 --- a/src/bin/pg_rewind/t/001_basic.pl +++ b/src/bin/pg_rewind/t/001_basic.pl @@ -18,6 +18,12 @@ sub run_test RewindTest::setup_cluster($test_mode); RewindTest::start_primary(); + # Create an in-place tablespace with some data on it. + primary_psql("CREATE TABLESPACE space_test LOCATION ''"); + primary_psql("CREATE TABLE space_tbl (d text) TABLESPACE space_test"); + primary_psql( + "INSERT INTO space_tbl VALUES ('in primary, before promotion')"); + # Create a test table and insert a row in primary. primary_psql("CREATE TABLE tbl1 (d text)"); primary_psql("INSERT INTO tbl1 VALUES ('in primary')"); @@ -78,6 +84,13 @@ sub run_test "insert into drop_tbl values ('in primary, after promotion')"); primary_psql("DROP TABLE drop_tbl"); + # Insert some data in the in-place tablespace for the old primary and + # the standby. + primary_psql( + "INSERT INTO space_tbl VALUES ('in primary, after promotion')"); + standby_psql( + "INSERT INTO space_tbl VALUES ('in standby, after promotion')"); + # Before running pg_rewind, do a couple of extra tests with several # option combinations. As the code paths taken by those tests # do not change for the "local" and "remote" modes, just run them @@ -146,6 +159,13 @@ sub run_test RewindTest::run_pg_rewind($test_mode); check_query( + 'SELECT * FROM space_tbl ORDER BY d', + qq(in primary, before promotion +in standby, after promotion +), + 'table content'); + + check_query( 'SELECT * FROM tbl1', qq(in primary in primary, before promotion diff --git a/src/bin/pg_rewind/t/RewindTest.pm b/src/bin/pg_rewind/t/RewindTest.pm index 4957791e94d..8fbbd521cb5 100644 --- a/src/bin/pg_rewind/t/RewindTest.pm +++ b/src/bin/pg_rewind/t/RewindTest.pm @@ -131,6 +131,7 @@ sub setup_cluster $node_primary->append_conf( 'postgresql.conf', qq( wal_keep_size = 320MB +allow_in_place_tablespaces = on )); return; } |