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

Commit7228d02

Browse files
committed
Throw error for mismatched pg_upgrade clusters
If someone removes the 'postgres' database from the old cluster and thenew cluster has a 'postgres' database, the number of databases will notmatch. We actually could upgrade such a setup, but it would violate the1-to-1 mapping of database counts, so we throw an error instead.Previously they got an error during the upgrade, and not at the checkstage; PG 9.0.4 does the same.
1 parent0341944 commit7228d02

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
staticvoidset_locale_and_encoding(ClusterInfo*cluster);
14-
staticvoidcheck_new_db_is_empty(void);
14+
staticvoidcheck_new_cluster_is_empty(void);
15+
staticvoidcheck_old_cluster_has_new_cluster_dbs(void);
1516
staticvoidcheck_locale_and_encoding(ControlData*oldctrl,
1617
ControlData*newctrl);
1718
staticvoidcheck_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
staticvoid
344-
check_new_db_is_empty(void)
348+
check_new_cluster_is_empty(void)
345349
{
346350
intdbnum;
347-
boolfound= 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+
staticvoid
378+
check_old_cluster_has_new_cluster_dbs(void)
379+
{
380+
intold_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)

[8]ページ先頭

©2009-2025 Movatter.jp