Skip to content

Commit a72d613

Browse files
committed
Fix pg_dumpall with in-place tablespaces
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 backpatch 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.xiyuan.zr@alibaba-inc.com
1 parent f05b1fa commit a72d613

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/bin/pg_dump/pg_dumpall.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,16 @@ dumpTablespaces(PGconn *conn)
12861286
appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
12871287

12881288
appendPQExpBufferStr(buf, " LOCATION ");
1289-
appendStringLiteralConn(buf, spclocation, conn);
1289+
1290+
/*
1291+
* In-place tablespaces use a relative path, and need to be dumped
1292+
* with an empty string as location.
1293+
*/
1294+
if (is_absolute_path(spclocation))
1295+
appendStringLiteralConn(buf, spclocation, conn);
1296+
else
1297+
appendStringLiteralConn(buf, "", conn);
1298+
12901299
appendPQExpBufferStr(buf, ";\n");
12911300

12921301
if (spcoptions && spcoptions[0] != '\0')

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

+16
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,22 @@
19071907
},
19081908
},
19091909

1910+
'CREATE TABLESPACE regress_dump_tablespace' => {
1911+
create_order => 2,
1912+
create_sql => q(
1913+
SET allow_in_place_tablespaces = on;
1914+
CREATE TABLESPACE regress_dump_tablespace
1915+
OWNER regress_dump_test_role LOCATION ''),
1916+
regexp =>
1917+
qr/^CREATE TABLESPACE regress_dump_tablespace OWNER regress_dump_test_role LOCATION '';/m,
1918+
like => {
1919+
pg_dumpall_dbprivs => 1,
1920+
pg_dumpall_exclude => 1,
1921+
pg_dumpall_globals => 1,
1922+
pg_dumpall_globals_clean => 1,
1923+
},
1924+
},
1925+
19101926
'CREATE DATABASE regression_invalid...' => {
19111927
create_order => 1,
19121928
create_sql => q(

0 commit comments

Comments
 (0)