Skip to content

Commit 0a5f119

Browse files
committed
A toast relid field are no longer needed in pg_upgrade's rel arrays, so
remove them. Also other renaming.
1 parent 0eb59c4 commit 0a5f119

File tree

4 files changed

+63
-76
lines changed

4 files changed

+63
-76
lines changed

contrib/pg_upgrade/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ check_new_db_is_empty(void)
362362
}
363363
}
364364

365-
dbarr_free(&new_cluster.dbarr);
365+
free_db_and_rel_infos(&new_cluster.dbarr);
366366

367367
if (found)
368368
pg_log(PG_FATAL, "New cluster is not empty; exiting\n");

contrib/pg_upgrade/info.c

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
#include "access/transam.h"
1313

1414

15-
static void get_db_infos(ClusterInfo *cluster);
16-
static void print_db_arr(ClusterInfo *cluster);
17-
static void print_rel_arr(RelInfoArr *arr);
18-
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
19-
static void free_rel_arr(RelInfoArr *rel_arr);
2015
static void create_rel_filename_map(const char *old_data, const char *new_data,
2116
const DbInfo *old_db, const DbInfo *new_db,
2217
const RelInfo *old_rel, const RelInfo *new_rel,
2318
FileNameMap *map);
19+
static void get_db_infos(ClusterInfo *cluster);
20+
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
21+
static void free_rel_infos(RelInfoArr *rel_arr);
22+
static void print_db_infos(DbInfoArr *dbinfo);
23+
static void print_rel_infos(RelInfoArr *arr);
2424

2525

2626
/*
@@ -111,15 +111,15 @@ create_rel_filename_map(const char *old_data, const char *new_data,
111111

112112

113113
void
114-
print_maps(FileNameMap *maps, int n, const char *dbName)
114+
print_maps(FileNameMap *maps, int n_maps, const char *db_name)
115115
{
116116
if (log_opts.debug)
117117
{
118118
int mapnum;
119119

120-
pg_log(PG_DEBUG, "mappings for db %s:\n", dbName);
120+
pg_log(PG_DEBUG, "mappings for db %s:\n", db_name);
121121

122-
for (mapnum = 0; mapnum < n; mapnum++)
122+
for (mapnum = 0; mapnum < n_maps; mapnum++)
123123
pg_log(PG_DEBUG, "%s.%s: %u to %u\n",
124124
maps[mapnum].nspname, maps[mapnum].relname,
125125
maps[mapnum].old_relfilenode,
@@ -130,6 +130,30 @@ print_maps(FileNameMap *maps, int n, const char *dbName)
130130
}
131131

132132

133+
/*
134+
* get_db_and_rel_infos()
135+
*
136+
* higher level routine to generate dbinfos for the database running
137+
* on the given "port". Assumes that server is already running.
138+
*/
139+
void
140+
get_db_and_rel_infos(ClusterInfo *cluster)
141+
{
142+
int dbnum;
143+
144+
get_db_infos(cluster);
145+
146+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
147+
get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
148+
149+
if (log_opts.debug)
150+
{
151+
pg_log(PG_DEBUG, "%s databases\n", CLUSTER_NAME(cluster));
152+
print_db_infos(&cluster->dbarr);
153+
}
154+
}
155+
156+
133157
/*
134158
* get_db_infos()
135159
*
@@ -144,9 +168,7 @@ get_db_infos(ClusterInfo *cluster)
144168
int ntups;
145169
int tupnum;
146170
DbInfo *dbinfos;
147-
int i_datname;
148-
int i_oid;
149-
int i_spclocation;
171+
int i_datname, i_oid, i_spclocation;
150172

151173
res = executeQueryOrDie(conn,
152174
"SELECT d.oid, d.datname, t.spclocation "
@@ -182,27 +204,6 @@ get_db_infos(ClusterInfo *cluster)
182204
}
183205

184206

185-
/*
186-
* get_db_and_rel_infos()
187-
*
188-
* higher level routine to generate dbinfos for the database running
189-
* on the given "port". Assumes that server is already running.
190-
*/
191-
void
192-
get_db_and_rel_infos(ClusterInfo *cluster)
193-
{
194-
int dbnum;
195-
196-
get_db_infos(cluster);
197-
198-
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
199-
get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
200-
201-
if (log_opts.debug)
202-
print_db_arr(cluster);
203-
}
204-
205-
206207
/*
207208
* get_rel_infos()
208209
*
@@ -224,27 +225,20 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
224225
int num_rels = 0;
225226
char *nspname = NULL;
226227
char *relname = NULL;
227-
int i_spclocation = -1;
228-
int i_nspname = -1;
229-
int i_relname = -1;
230-
int i_oid = -1;
231-
int i_relfilenode = -1;
232-
int i_reltoastrelid = -1;
228+
int i_spclocation, i_nspname, i_relname, i_oid, i_relfilenode;
233229
char query[QUERY_ALLOC];
234230

235231
/*
236232
* pg_largeobject contains user data that does not appear in pg_dumpall
237233
* --schema-only output, so we have to copy that system table heap and
238-
* index. Ideally we could just get the relfilenode from template1 but
239-
* pg_largeobject_loid_pn_index's relfilenode can change if the table was
240-
* reindexed so we get the relfilenode for each database and upgrade it as
241-
* a normal user table.
242-
* Order by tablespace so we can cache the directory contents efficiently.
234+
* index. We could grab the pg_largeobject oids from template1, but
235+
* it is easy to treat it as a normal table.
236+
* Order by oid so we can join old/new structures efficiently.
243237
*/
244238

245239
snprintf(query, sizeof(query),
246-
"SELECT DISTINCT c.oid, n.nspname, c.relname, "
247-
" c.relfilenode, c.reltoastrelid, t.spclocation "
240+
"SELECT c.oid, n.nspname, c.relname, "
241+
" c.relfilenode, t.spclocation "
248242
"FROM pg_catalog.pg_class c JOIN "
249243
" pg_catalog.pg_namespace n "
250244
" ON c.relnamespace = n.oid "
@@ -256,10 +250,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
256250
" n.nspname = 'pg_catalog' "
257251
" AND relname IN "
258252
" ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
259-
" AND relkind IN ('r','t', 'i'%s)"
260-
"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
261-
" c.reltoastrelid, t.spclocation, "
262-
" n.nspname "
253+
" AND relkind IN ('r','t', 'i'%s) "
263254
/* we preserve pg_class.oid so we sort by it to match old/new */
264255
"ORDER BY 1;",
265256
FirstNormalObjectId,
@@ -280,7 +271,6 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
280271
i_nspname = PQfnumber(res, "nspname");
281272
i_relname = PQfnumber(res, "relname");
282273
i_relfilenode = PQfnumber(res, "relfilenode");
283-
i_reltoastrelid = PQfnumber(res, "reltoastrelid");
284274
i_spclocation = PQfnumber(res, "spclocation");
285275

286276
for (relnum = 0; relnum < ntups; relnum++)
@@ -297,7 +287,6 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
297287
strlcpy(curr->relname, relname, sizeof(curr->relname));
298288

299289
curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
300-
curr->toastrelid = atooid(PQgetvalue(res, relnum, i_reltoastrelid));
301290

302291
tblspace = PQgetvalue(res, relnum, i_spclocation);
303292
/* if no table tablespace, use the database tablespace */
@@ -314,43 +303,42 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
314303
}
315304

316305

317-
static void
318-
free_rel_arr(RelInfoArr *rel_arr)
319-
{
320-
pg_free(rel_arr->rels);
321-
rel_arr->nrels = 0;
322-
}
323-
324-
325306
void
326-
dbarr_free(DbInfoArr *db_arr)
307+
free_db_and_rel_infos(DbInfoArr *db_arr)
327308
{
328309
int dbnum;
329310

330311
for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
331-
free_rel_arr(&db_arr->dbs[dbnum].rel_arr);
312+
free_rel_infos(&db_arr->dbs[dbnum].rel_arr);
313+
pg_free(db_arr->dbs);
332314
db_arr->ndbs = 0;
333315
}
334316

335317

336318
static void
337-
print_db_arr(ClusterInfo *cluster)
319+
free_rel_infos(RelInfoArr *rel_arr)
338320
{
339-
int dbnum;
321+
pg_free(rel_arr->rels);
322+
rel_arr->nrels = 0;
323+
}
340324

341-
pg_log(PG_DEBUG, "%s databases\n", CLUSTER_NAME(cluster));
342325

343-
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
326+
static void
327+
print_db_infos(DbInfoArr *db_arr)
328+
{
329+
int dbnum;
330+
331+
for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
344332
{
345-
pg_log(PG_DEBUG, "Database: %s\n", cluster->dbarr.dbs[dbnum].db_name);
346-
print_rel_arr(&cluster->dbarr.dbs[dbnum].rel_arr);
333+
pg_log(PG_DEBUG, "Database: %s\n", db_arr->dbs[dbnum].db_name);
334+
print_rel_infos(&db_arr->dbs[dbnum].rel_arr);
347335
pg_log(PG_DEBUG, "\n\n");
348336
}
349337
}
350338

351339

352340
static void
353-
print_rel_arr(RelInfoArr *arr)
341+
print_rel_infos(RelInfoArr *arr)
354342
{
355343
int relnum;
356344

contrib/pg_upgrade/pg_upgrade.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ create_new_objects(void)
281281
check_ok();
282282

283283
/* regenerate now that we have objects in the databases */
284-
dbarr_free(&new_cluster.dbarr);
284+
free_db_and_rel_infos(&new_cluster.dbarr);
285285
get_db_and_rel_infos(&new_cluster);
286286

287287
uninstall_support_functions_from_new_cluster();
@@ -428,8 +428,8 @@ cleanup(void)
428428
pg_free(os_info.tablespaces[tblnum]);
429429
pg_free(os_info.tablespaces);
430430

431-
dbarr_free(&old_cluster.dbarr);
432-
dbarr_free(&new_cluster.dbarr);
431+
free_db_and_rel_infos(&old_cluster.dbarr);
432+
free_db_and_rel_infos(&new_cluster.dbarr);
433433
pg_free(log_opts.filename);
434434
pg_free(os_info.user);
435435
pg_free(old_cluster.controldata.lc_collate);

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ typedef struct
6969
char relname[NAMEDATALEN]; /* relation name */
7070
Oid reloid; /* relation oid */
7171
Oid relfilenode; /* relation relfile node */
72-
Oid toastrelid; /* oid of the toast relation */
7372
char tablespace[MAXPGPATH]; /* relations tablespace path */
7473
} RelInfo;
7574

@@ -331,9 +330,9 @@ FileNameMap *gen_db_file_maps(DbInfo *old_db,
331330
DbInfo *new_db, int *nmaps, const char *old_pgdata,
332331
const char *new_pgdata);
333332
void get_db_and_rel_infos(ClusterInfo *cluster);
334-
void dbarr_free(DbInfoArr *db_arr);
335-
void print_maps(FileNameMap *maps, int n,
336-
const char *dbName);
333+
void free_db_and_rel_infos(DbInfoArr *db_arr);
334+
void print_maps(FileNameMap *maps, int n,
335+
const char *db_name);
337336

338337
/* option.c */
339338

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy