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 | 7f8d090b8966ef098f45537d42e47e296210145f (patch) | |
tree | 4f08bc38955d95543882bd4b913800375e1f0ab9 /src | |
parent | 2ccc4e972eb85829a8fe8d39fc5ce4d770ac2e2e (diff) | |
download | postgresql-7f8d090b8966ef098f45537d42e47e296210145f.tar.gz postgresql-7f8d090b8966ef098f45537d42e47e296210145f.zip |
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 | ||||
-rw-r--r-- | src/bin/pg_upgrade/info.c | 15 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index c4b6ae85aa7..3461335d102 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) { diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c index e158c9ff8b0..e980c9f989f 100644 --- a/src/bin/pg_upgrade/info.c +++ b/src/bin/pg_upgrade/info.c @@ -140,6 +140,7 @@ create_rel_filename_map(const char *old_data, const char *new_data, 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) { /* @@ -147,16 +148,24 @@ create_rel_filename_map(const char *old_data, const char *new_data, * 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; } |