Skip to content

Commit 84b8fca

Browse files
committed
Adjust pg_upgrade "new database skip" code, e.g. 'postgres', to more
cleanly handle old/new database mismatches.
1 parent 7ed3605 commit 84b8fca

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

contrib/pg_upgrade/relfilenode.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
4141

4242
/* Scan the old cluster databases and transfer their files */
4343
for (old_dbnum = new_dbnum = 0;
44-
old_dbnum < old_db_arr->ndbs && new_dbnum < new_db_arr->ndbs;
44+
old_dbnum < old_db_arr->ndbs;
4545
old_dbnum++, new_dbnum++)
4646
{
47-
DbInfo *old_db = &old_db_arr->dbs[old_dbnum];
48-
DbInfo *new_db = &new_db_arr->dbs[new_dbnum];
47+
DbInfo *old_db = &old_db_arr->dbs[old_dbnum], *new_db;
4948
FileNameMap *mappings;
5049
int n_maps;
5150
pageCnvCtx *pageConverter = NULL;
@@ -55,13 +54,16 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
5554
* but not in the old, e.g. "postgres". (The user might
5655
* have removed the 'postgres' database from the old cluster.)
5756
*/
58-
while (strcmp(old_db->db_name, new_db->db_name) != 0 &&
59-
new_dbnum < new_db_arr->ndbs)
60-
new_db = &new_db_arr->dbs[++new_dbnum];
57+
for (; new_dbnum < new_db_arr->ndbs; new_dbnum++)
58+
{
59+
new_db = &new_db_arr->dbs[new_dbnum];
60+
if (strcmp(old_db->db_name, new_db->db_name) == 0)
61+
break;
62+
}
6163

62-
if (strcmp(old_db->db_name, new_db->db_name) != 0)
63-
pg_log(PG_FATAL, "old and new databases have different names: old \"%s\", new \"%s\"\n",
64-
old_db->db_name, new_db->db_name);
64+
if (new_dbnum >= new_db_arr->ndbs)
65+
pg_log(PG_FATAL, "old database \"%s\" not found in the new cluster\n",
66+
old_db->db_name);
6567

6668
n_maps = 0;
6769
mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata,

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