Fix pg_dumpall with in-place tablespaces
authorMichael Paquier <[email protected]>
Tue, 8 Aug 2023 23:56:05 +0000 (08:56 +0900)
committerMichael Paquier <[email protected]>
Tue, 8 Aug 2023 23:56:05 +0000 (08:56 +0900)
In-place tablespaces would be dumped with the path produced by
pg_tablespace_location(), which is in this case a relative path built as
pg_tblspc/OID, but this would fail to restore as such tablespaces need
to use an empty string as location.  In order to detect if an in-place
tablespace is used, this commit checks if the path returned is relative
and adapts the dump contents in consequence.

Like the other changes related to in-place tablespaces, no back is
done as these are only intended for development purposes.  Rui Zhao has
fixed the code, while the test is from me.

Author: Rui Zhao, Michael Paquier
Discussion: https://postgr.es/m/80c80b4a-b87b-456f-bd46-1ae326601d79[email protected]

src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/t/002_pg_dump.pl

index 0ab52ca81d785d747922a85b6156c70dc5e5ad50..e2a9733d34897b534dc10a6aa26acfecfa025eb3 100644 (file)
@@ -1286,7 +1286,16 @@ dumpTablespaces(PGconn *conn)
        appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
 
        appendPQExpBufferStr(buf, " LOCATION ");
-       appendStringLiteralConn(buf, spclocation, conn);
+
+       /*
+        * In-place tablespaces use a relative path, and need to be dumped
+        * with an empty string as location.
+        */
+       if (is_absolute_path(spclocation))
+           appendStringLiteralConn(buf, spclocation, conn);
+       else
+           appendStringLiteralConn(buf, "", conn);
+
        appendPQExpBufferStr(buf, ";\n");
 
        if (spcoptions && spcoptions[0] != '\0')
index 0efeb3367d54d26e08dac64ce9444a31b4e496d6..6ad83102874ca56a59379ed5b06397f75a26fb84 100644 (file)
@@ -1907,6 +1907,22 @@ my %tests = (
        },
    },
 
+   'CREATE TABLESPACE regress_dump_tablespace' => {
+       create_order => 2,
+       create_sql => q(
+           SET allow_in_place_tablespaces = on;
+           CREATE TABLESPACE regress_dump_tablespace
+           OWNER regress_dump_test_role LOCATION ''),
+       regexp =>
+         qr/^CREATE TABLESPACE regress_dump_tablespace OWNER regress_dump_test_role LOCATION '';/m,
+       like => {
+           pg_dumpall_dbprivs => 1,
+           pg_dumpall_exclude => 1,
+           pg_dumpall_globals => 1,
+           pg_dumpall_globals_clean => 1,
+       },
+   },
+
    'CREATE DATABASE regression_invalid...' => {
        create_order => 1,
        create_sql => q(