aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_dumpall.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_dump/pg_dumpall.c')
-rw-r--r--src/bin/pg_dump/pg_dumpall.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index d98c83e099c..4b166050cda 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -1412,6 +1412,24 @@ dumpCreateDB(PGconn *conn)
appendPQExpBufferStr(buf, ";\n");
}
+ else if (strcmp(dbtablespace, "pg_default") != 0 && !no_tablespaces)
+ {
+ /*
+ * Cannot change tablespace of the database we're connected to,
+ * so to move "postgres" to another tablespace, we connect to
+ * "template1", and vice versa.
+ */
+ if (strcmp(dbname, "postgres") == 0)
+ appendPQExpBuffer(buf, "\\connect template1\n");
+ else
+ appendPQExpBuffer(buf, "\\connect postgres\n");
+
+ appendPQExpBuffer(buf, "ALTER DATABASE %s SET TABLESPACE %s;\n",
+ fdbname, fmtId(dbtablespace));
+
+ /* connect to original database */
+ appendPQExpBuffer(buf, "\\connect %s\n", fdbname);
+ }
if (binary_upgrade)
{