Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit35d2fc1

Browse files
committed
pg_dump, pg_upgrade: allow postgres/template1 tablespace moves
Modify pg_dump to restore postgres/template1 databases to non-defaulttablespaces by switching out of the database to be moved, then switchingback.Also, to fix potentially cases where the old/new tablespaces might notmatch, fix pg_upgrade to process new/old tablespaces separately in allcases.Report by Marti RaudseppPatch by Marti Raudsepp, meBackpatch through 9.0
1 parent7d07128 commit35d2fc1

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

‎contrib/pg_upgrade/info.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,32 @@ create_rel_filename_map(const char *old_data, const char *new_data,
140140
constRelInfo*old_rel,constRelInfo*new_rel,
141141
FileNameMap*map)
142142
{
143+
/* In case old/new tablespaces don't match, do them separately. */
143144
if (strlen(old_rel->tablespace)==0)
144145
{
145146
/*
146147
* relation belongs to the default tablespace, hence relfiles should
147148
* exist in the data directories.
148149
*/
149150
map->old_tablespace=old_data;
150-
map->new_tablespace=new_data;
151151
map->old_tablespace_suffix="/base";
152-
map->new_tablespace_suffix="/base";
153152
}
154153
else
155154
{
156155
/* relation belongs to a tablespace, so use the tablespace location */
157156
map->old_tablespace=old_rel->tablespace;
158-
map->new_tablespace=new_rel->tablespace;
159157
map->old_tablespace_suffix=old_cluster.tablespace_suffix;
158+
}
159+
160+
/* Do the same for new tablespaces */
161+
if (strlen(new_rel->tablespace)==0)
162+
{
163+
map->new_tablespace=new_data;
164+
map->new_tablespace_suffix="/base";
165+
}
166+
else
167+
{
168+
map->new_tablespace=new_rel->tablespace;
160169
map->new_tablespace_suffix=new_cluster.tablespace_suffix;
161170
}
162171

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,24 @@ dumpCreateDB(PGconn *conn)
13991399
appendPQExpBufferStr(buf,";\n");
14001400
}
14011401
}
1402+
elseif (strcmp(dbtablespace,"pg_default")!=0&& !no_tablespaces)
1403+
{
1404+
/*
1405+
* Cannot change tablespace of the database we're connected to,
1406+
* so to move "postgres" to another tablespace, we connect to
1407+
* "template1", and vice versa.
1408+
*/
1409+
if (strcmp(dbname,"postgres")==0)
1410+
appendPQExpBuffer(buf,"\\connect template1\n");
1411+
else
1412+
appendPQExpBuffer(buf,"\\connect postgres\n");
1413+
1414+
appendPQExpBuffer(buf,"ALTER DATABASE %s SET TABLESPACE %s;\n",
1415+
fdbname,fmtId(dbtablespace));
1416+
1417+
/* connect to original database */
1418+
appendPQExpBuffer(buf,"\\connect %s\n",fdbname);
1419+
}
14021420

14031421
if (binary_upgrade)
14041422
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp