Skip to content

Commit f75383e

Browse files
committed
In pg_upgrade, track only one copy of namespace/relname in FileNameMap
because the old and new values are identical.
1 parent 519c008 commit f75383e

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

contrib/pg_upgrade/info.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
5454
if (strcmp(old_rel->nspname, "pg_toast") == 0)
5555
continue;
5656

57-
/* old/new non-toast relation names match */
57+
/* old/new relation names always match */
5858
new_rel = relarr_lookup_rel_name(&new_cluster, &new_db->rel_arr,
5959
old_rel->nspname, old_rel->relname);
6060

@@ -135,11 +135,9 @@ create_rel_filename_map(const char *old_data, const char *new_data,
135135
map->old_relfilenode = old_rel->relfilenode;
136136
map->new_relfilenode = new_rel->relfilenode;
137137

138-
/* used only for logging and error reporing */
139-
snprintf(map->old_nspname, sizeof(map->old_nspname), "%s", old_rel->nspname);
140-
snprintf(map->new_nspname, sizeof(map->new_nspname), "%s", new_rel->nspname);
141-
snprintf(map->old_relname, sizeof(map->old_relname), "%s", old_rel->relname);
142-
snprintf(map->new_relname, sizeof(map->new_relname), "%s", new_rel->relname);
138+
/* used only for logging and error reporing, old/new are identical */
139+
snprintf(map->nspname, sizeof(map->nspname), "%s", old_rel->nspname);
140+
snprintf(map->relname, sizeof(map->relname), "%s", old_rel->relname);
143141
}
144142

145143

@@ -153,10 +151,9 @@ print_maps(FileNameMap *maps, int n, const char *dbName)
153151
pg_log(PG_DEBUG, "mappings for db %s:\n", dbName);
154152

155153
for (mapnum = 0; mapnum < n; mapnum++)
156-
pg_log(PG_DEBUG, "%s.%s:%u ==> %s.%s:%u\n",
157-
maps[mapnum].old_nspname, maps[mapnum].old_relname,
154+
pg_log(PG_DEBUG, "%s.%s: %u to %u\n",
155+
maps[mapnum].nspname, maps[mapnum].relname,
158156
maps[mapnum].old_relfilenode,
159-
maps[mapnum].new_nspname, maps[mapnum].new_relname,
160157
maps[mapnum].new_relfilenode);
161158

162159
pg_log(PG_DEBUG, "\n\n");
@@ -265,7 +262,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
265262
char query[QUERY_ALLOC];
266263

267264
/*
268-
* pg_largeobject contains user data that does not appear the pg_dumpall
265+
* pg_largeobject contains user data that does not appear in pg_dumpall
269266
* --schema-only output, so we have to copy that system table heap and
270267
* index. Ideally we could just get the relfilenode from template1 but
271268
* pg_largeobject_loid_pn_index's relfilenode can change if the table was

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ typedef struct
9494
Oid old_relfilenode;
9595
Oid new_relfilenode;
9696
/* the rest are used only for logging and error reporting */
97-
char old_nspname[NAMEDATALEN]; /* namespaces */
98-
char new_nspname[NAMEDATALEN];
99-
/* old/new relnames differ for toast tables and toast indexes */
100-
char old_relname[NAMEDATALEN];
101-
char new_relname[NAMEDATALEN];
97+
char nspname[NAMEDATALEN]; /* namespaces */
98+
char relname[NAMEDATALEN];
10299
} FileNameMap;
103100

104101
/*

contrib/pg_upgrade/relfilenode.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ static void transfer_single_new_db(pageCnvCtx *pageConverter,
1717
FileNameMap *maps, int size);
1818
static void transfer_relfile(pageCnvCtx *pageConverter,
1919
const char *fromfile, const char *tofile,
20-
const char *old_nspname, const char *new_nspname,
21-
const char *old_relname, const char *new_relname);
20+
const char *nspname, const char *relname);
2221

2322
/* used by scandir(), must be global */
2423
char scandir_file_pattern[MAXPGPATH];
@@ -149,8 +148,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
149148
*/
150149
unlink(new_file);
151150
transfer_relfile(pageConverter, old_file, new_file,
152-
maps[mapnum].old_nspname, maps[mapnum].new_nspname,
153-
maps[mapnum].old_relname, maps[mapnum].new_relname);
151+
maps[mapnum].nspname, maps[mapnum].relname);
154152

155153
/* fsm/vm files added in PG 8.4 */
156154
if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804)
@@ -173,8 +171,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
173171

174172
unlink(new_file);
175173
transfer_relfile(pageConverter, old_file, new_file,
176-
maps[mapnum].old_nspname, maps[mapnum].new_nspname,
177-
maps[mapnum].old_relname, maps[mapnum].new_relname);
174+
maps[mapnum].nspname, maps[mapnum].relname);
178175
}
179176
}
180177
}
@@ -201,8 +198,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
201198

202199
unlink(new_file);
203200
transfer_relfile(pageConverter, old_file, new_file,
204-
maps[mapnum].old_nspname, maps[mapnum].new_nspname,
205-
maps[mapnum].old_relname, maps[mapnum].new_relname);
201+
maps[mapnum].nspname, maps[mapnum].relname);
206202
}
207203
}
208204
}
@@ -224,8 +220,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
224220
*/
225221
static void
226222
transfer_relfile(pageCnvCtx *pageConverter, const char *old_file,
227-
const char *new_file, const char *old_nspname, const char *new_nspname,
228-
const char *old_relname, const char *new_relname)
223+
const char *new_file, const char *nspname, const char *relname)
229224
{
230225
const char *msg;
231226

@@ -238,18 +233,17 @@ transfer_relfile(pageCnvCtx *pageConverter, const char *old_file,
238233
pg_log(PG_INFO, "copying %s to %s\n", old_file, new_file);
239234

240235
if ((msg = copyAndUpdateFile(pageConverter, old_file, new_file, true)) != NULL)
241-
pg_log(PG_FATAL, "error while copying %s.%s(%s) to %s.%s(%s): %s\n",
242-
old_nspname, old_relname, old_file, new_nspname, new_relname, new_file, msg);
236+
pg_log(PG_FATAL, "error while copying %s.%s (%s to %s): %s\n",
237+
nspname, relname, old_file, new_file, msg);
243238
}
244239
else
245240
{
246241
pg_log(PG_INFO, "linking %s to %s\n", old_file, new_file);
247242

248243
if ((msg = linkAndUpdateFile(pageConverter, old_file, new_file)) != NULL)
249244
pg_log(PG_FATAL,
250-
"error while creating link from %s.%s(%s) to %s.%s(%s): %s\n",
251-
old_nspname, old_relname, old_file, new_nspname, new_relname,
252-
new_file, msg);
245+
"error while creating link from %s.%s (%s to %s): %s\n",
246+
nspname, relname, old_file, new_file, msg);
253247
}
254248
return;
255249
}

0 commit comments

Comments
 (0)