On Wed, Aug 02, 2023 at 10:38:00PM +0800, Rui Zhao wrote: > However, when using pg_dump to back up this in-place tablespace, it > is dumped with a different path: > CREATE TABLESPACE space_test LOCATION 'pg_tblspc/<oid>' > This can be confusing because it does not match the initial path > that we created. Additionally, pg_restore cannot restore this > in-place tablespace because the CREATE TABLESPACE command only > supports an empty path for creating in-place tablespaces.
Yes, the dump part is a different issue. Using a relative path is not fine when restoring the tablespace. > You are correct. I have made the necessary modifications to ensure > compatibility with in-place tablespaces. Please find the updated > code attached. + /* Allow to create in-place tablespace. */ + if (!is_absolute_path(spclocation)) + appendPQExpBuffer(buf, "SET allow_in_place_tablespaces = true;\n"); + appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname); appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner)); As you say, This change in pg_dumpall.c takes care of an issue related to the dumps of in-place tablespaces, not only pg_upgrade. See for example on HEAD: $ psql -c "CREATE TABLESPACE popo LOCATION ''" $ pg_dumpall | grep TABLESPACE CREATE TABLESPACE popo OWNER postgres LOCATION 'pg_tblspc/16385'; And restoring this dump would be incorrect. I think that we'd better be doing something like that for the dump part, as of: @@ -1286,7 +1286,12 @@ dumpTablespaces(PGconn *conn) appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner)); appendPQExpBufferStr(buf, " LOCATION "); - appendStringLiteralConn(buf, spclocation, conn); + + /* In-place tablespaces use a relative path */ + if (is_absolute_path(spclocation)) + appendStringLiteralConn(buf, spclocation, conn); + else + appendPQExpBufferStr(buf, "'';\n"); I don't have a good feeling about enforcing allow_in_place_tablespaces in the connection creating the tablespace, as it can be useful to let the restore of the dump fail if this GUC is disabled in the new cluster, so as one can check that no in-place tablespaces are left around on the new cluster restoring the contents of the dump. -- Michael
signature.asc
Description: PGP signature