diff options
author | Bruce Momjian <bruce@momjian.us> | 2015-09-11 15:51:11 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2015-09-11 15:51:11 -0400 |
commit | 35d2fc1f299a977483a1ac6d08bfbda104ad2b25 (patch) | |
tree | 8f2f84e574534c89087bbf2ab65295612c0fd860 /src | |
parent | 7d0712890d1e18379394cec33b01edb7102928de (diff) |
pg_dump, pg_upgrade: allow postgres/template1 tablespace moves
Modify pg_dump to restore postgres/template1 databases to non-default
tablespaces by switching out of the database to be moved, then switching
back.
Also, to fix potentially cases where the old/new tablespaces might not
match, fix pg_upgrade to process new/old tablespaces separately in all
cases.
Report by Marti Raudsepp
Patch by Marti Raudsepp, me
Backpatch through 9.0
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_dump/pg_dumpall.c | 18 |
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 19467a4fecc..8cae1e0d2e9 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -1399,6 +1399,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) { |