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)
{
const RelInfo *old_rel, const RelInfo *new_rel,
FileNameMap *map)
{
+ /* In case old/new tablespaces don't match, do them separately. */
if (strlen(old_rel->tablespace) == 0)
{
/*
* exist in the data directories.
*/
map->old_tablespace = old_data;
- map->new_tablespace = new_data;
map->old_tablespace_suffix = "/base";
- map->new_tablespace_suffix = "/base";
}
else
{
/* relation belongs to a tablespace, so use the tablespace location */
map->old_tablespace = old_rel->tablespace;
- map->new_tablespace = new_rel->tablespace;
map->old_tablespace_suffix = old_cluster.tablespace_suffix;
+ }
+
+ /* Do the same for new tablespaces */
+ if (strlen(new_rel->tablespace) == 0)
+ {
+ map->new_tablespace = new_data;
+ map->new_tablespace_suffix = "/base";
+ }
+ else
+ {
+ map->new_tablespace = new_rel->tablespace;
map->new_tablespace_suffix = new_cluster.tablespace_suffix;
}