Skip to content

Commit 7228d02

Browse files
committed
Throw error for mismatched pg_upgrade clusters
If someone removes the 'postgres' database from the old cluster and the new cluster has a 'postgres' database, the number of databases will not match. We actually could upgrade such a setup, but it would violate the 1-to-1 mapping of database counts, so we throw an error instead. Previously they got an error during the upgrade, and not at the check stage; PG 9.0.4 does the same.
1 parent 0341944 commit 7228d02

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

contrib/pg_upgrade/check.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212

1313
static void set_locale_and_encoding(ClusterInfo *cluster);
14-
static void check_new_db_is_empty(void);
14+
static void check_new_cluster_is_empty(void);
15+
static void check_old_cluster_has_new_cluster_dbs(void);
1516
static void check_locale_and_encoding(ControlData *oldctrl,
1617
ControlData *newctrl);
1718
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
@@ -112,7 +113,10 @@ check_new_cluster(void)
112113
{
113114
set_locale_and_encoding(&new_cluster);
114115

115-
check_new_db_is_empty();
116+
get_db_and_rel_infos(&new_cluster);
117+
118+
check_new_cluster_is_empty();
119+
check_old_cluster_has_new_cluster_dbs();
116120

117121
check_loadable_libraries();
118122

@@ -341,12 +345,9 @@ check_locale_and_encoding(ControlData *oldctrl,
341345

342346

343347
static void
344-
check_new_db_is_empty(void)
348+
check_new_cluster_is_empty(void)
345349
{
346350
int dbnum;
347-
bool found = false;
348-
349-
get_db_and_rel_infos(&new_cluster);
350351

351352
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
352353
{
@@ -358,15 +359,36 @@ check_new_db_is_empty(void)
358359
{
359360
/* pg_largeobject and its index should be skipped */
360361
if (strcmp(rel_arr->rels[relnum].nspname, "pg_catalog") != 0)
361-
{
362-
found = true;
363-
break;
364-
}
362+
pg_log(PG_FATAL, "New cluster database \"%s\" is not empty\n",
363+
new_cluster.dbarr.dbs[dbnum].db_name);
365364
}
366365
}
367366

368-
if (found)
369-
pg_log(PG_FATAL, "New cluster is not empty; exiting\n");
367+
}
368+
369+
370+
/*
371+
* If someone removes the 'postgres' database from the old cluster and
372+
* the new cluster has a 'postgres' database, the number of databases
373+
* will not match. We actually could upgrade such a setup, but it would
374+
* violate the 1-to-1 mapping of database counts, so we throw an error
375+
* instead.
376+
*/
377+
static void
378+
check_old_cluster_has_new_cluster_dbs(void)
379+
{
380+
int old_dbnum, new_dbnum;
381+
382+
for (new_dbnum = 0; new_dbnum < new_cluster.dbarr.ndbs; new_dbnum++)
383+
{
384+
for (old_dbnum = 0; old_dbnum < old_cluster.dbarr.ndbs; old_dbnum++)
385+
if (strcmp(old_cluster.dbarr.dbs[old_dbnum].db_name,
386+
new_cluster.dbarr.dbs[new_dbnum].db_name) == 0)
387+
break;
388+
if (old_dbnum == old_cluster.dbarr.ndbs)
389+
pg_log(PG_FATAL, "New cluster database \"%s\" does not exist in the old cluster\n",
390+
new_cluster.dbarr.dbs[new_dbnum].db_name);
391+
}
370392
}
371393

372394

contrib/pg_upgrade/relfilenode.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
3737

3838
prep_status("Restoring user relation files\n");
3939

40-
/*
41-
* If the user removed the 'postgres' database from the old cluster,
42-
* this will cause the database counts to not match and throw an error.
43-
* We could allow this to work because the new database is empty (we
44-
* checked), but we don't.
45-
*/
4640
if (old_db_arr->ndbs != new_db_arr->ndbs)
4741
pg_log(PG_FATAL, "old and new clusters have a different number of databases\n");
4842

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