public inbox for [email protected]
help / color / mirror / Atom feedFrom: Rui Zhao <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: pg_upgrade fails with in-place tablespace
Date: Sat, 29 Jul 2023 23:10:22 +0800
Message-ID: <[email protected]> (raw)
Hello postgres hackers,
Recently I encountered an issue: pg_upgrade fails when dealing with in-place tablespace. As we know, pg_upgrade uses pg_dumpall to dump objects and pg_restore to restore them. The problem seems to be that pg_dumpall is dumping in-place tablespace as relative path, which can't be restored.
Here is the error message of pg_upgrade:
psql:/home/postgres/postgresql/src/bin/pg_upgrade/tmp_check/t_002_pg_upgrade_new_node_data/pgdata/pg_upgrade_output.d/20230729T210058.329/dump/pg_upgrade_dump_globals.sql:36: ERROR: tablespace location must be an absolute path
To help reproduce the failure, I have attached a tap test. The test also fails with tablespace regression, and it change the default value of allow_in_place_tablespaces to true only for debug, so it may not be fit for production. However, it is enough to reproduce this failure.
I have also identified a solution for this problem, which I have included in the patch. The solution has two modifications:
1) Make the function pg_tablespace_location returns path "" with in-place tablespace, rather than relative path. Because the path of the in-place tablespace is always 'pg_tblspc/<oid>'.
2) Only check the tablespace with an absolute path in pg_upgrade.
There are also other solutions, such as supporting the creation of relative-path tablespace in function CreateTableSpace. But do we really need relative-path tablespace? I think in-place tablespace is enough by now. My solution may be more lightweight and harmless.
Thank you for your attention to this matter.
Best regards,
Rui Zhao
Attachments:
[application/octet-stream] 0001-Fix-pg_upgrade-fails-with-in-place-tablespace.patch (2.8K, ../[email protected]/3-0001-Fix-pg_upgrade-fails-with-in-place-tablespace.patch)
download | inline diff:
From 87ff3f9cccc4768f55e7390b27789ca47bccd025 Mon Sep 17 00:00:00 2001
From: Rui Zhao <[email protected]>
Date: Sat, 29 Jul 2023 22:49:42 +0800
Subject: [PATCH] Fix pg_upgrade failing with in-place tablespace.
---
src/backend/utils/adt/misc.c | 3 ++-
src/backend/utils/misc/guc_tables.c | 2 +-
src/bin/pg_upgrade/t/002_pg_upgrade.pl | 7 +++++++
src/bin/pg_upgrade/tablespace.c | 4 +++-
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 5d78d6dc06..baed55281b 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -341,8 +341,9 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
sourcepath)));
}
+ /* The path of the in-place tablespace is always pg_tblspc/<oid>. */
if (!S_ISLNK(st.st_mode))
- PG_RETURN_TEXT_P(cstring_to_text(sourcepath));
+ PG_RETURN_TEXT_P(cstring_to_text(""));
/*
* In presence of a link or a junction point, return the path pointing to.
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 15b51f2c5b..c433e0ce9b 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1834,7 +1834,7 @@ struct config_bool ConfigureNamesBool[] =
GUC_NOT_IN_SAMPLE
},
&allow_in_place_tablespaces,
- false,
+ true,
NULL, NULL, NULL
},
diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index a5688a1cf2..e8db54ae79 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -212,6 +212,13 @@ else
is($rc, 0, 'regression tests pass');
}
+# Test with in-place tablespace
+$oldnode->append_conf('postgresql.conf', 'allow_in_place_tablespaces = on');
+$oldnode->reload;
+$oldnode->safe_psql('postgres', "CREATE TABLESPACE space_test LOCATION ''");
+$oldnode->append_conf('postgresql.conf', 'allow_in_place_tablespaces = off');
+$oldnode->reload;
+
# Initialize a new node for the upgrade.
my $newnode = PostgreSQL::Test::Cluster->new('new_node');
diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c
index 69cef7fa6b..2a6ad6b910 100644
--- a/src/bin/pg_upgrade/tablespace.c
+++ b/src/bin/pg_upgrade/tablespace.c
@@ -45,11 +45,13 @@ get_tablespace_paths(void)
int i_spclocation;
char query[QUERY_ALLOC];
+ /* Only check the tablespace with an absolute path. */
snprintf(query, sizeof(query),
"SELECT pg_catalog.pg_tablespace_location(oid) AS spclocation "
"FROM pg_catalog.pg_tablespace "
"WHERE spcname != 'pg_default' AND "
- " spcname != 'pg_global'");
+ " spcname != 'pg_global' AND "
+ " pg_catalog.pg_tablespace_location(oid) ~ '^/'");
res = executeQueryOrDie(conn, "%s", query);
--
2.32.0.3.g01195cf9f
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: pg_upgrade fails with in-place tablespace
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox