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

Commita50d860

Browse files
committed
Allow pg_upgrade to upgrade an old cluster that doesn't have a
'postgres' database.
1 parent806a2ae commita50d860

File tree

3 files changed

+17
-45
lines changed

3 files changed

+17
-45
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
staticvoidset_locale_and_encoding(ClusterInfo*cluster);
1616
staticvoidcheck_new_cluster_is_empty(void);
17-
staticvoidcheck_old_cluster_has_new_cluster_dbs(void);
1817
staticvoidcheck_locale_and_encoding(ControlData*oldctrl,
1918
ControlData*newctrl);
2019
staticvoidcheck_is_super_user(ClusterInfo*cluster);
@@ -127,7 +126,6 @@ check_new_cluster(void)
127126

128127
check_new_cluster_is_empty();
129128
check_for_prepared_transactions(&new_cluster);
130-
check_old_cluster_has_new_cluster_dbs();
131129

132130
check_loadable_libraries();
133131

@@ -381,39 +379,6 @@ check_new_cluster_is_empty(void)
381379
}
382380

383381

384-
/*
385-
*If someone removes the 'postgres' database from the old cluster and
386-
*the new cluster has a 'postgres' database, the number of databases
387-
*will not match. We actually could upgrade such a setup, but it would
388-
*violate the 1-to-1 mapping of database counts, so we throw an error
389-
*instead. We would detect this as a database count mismatch during
390-
*upgrade, but we want to detect it during the check phase and report
391-
*the database name.
392-
*/
393-
staticvoid
394-
check_old_cluster_has_new_cluster_dbs(void)
395-
{
396-
intold_dbnum,
397-
new_dbnum;
398-
399-
for (new_dbnum=0;new_dbnum<new_cluster.dbarr.ndbs;new_dbnum++)
400-
{
401-
for (old_dbnum=0;old_dbnum<old_cluster.dbarr.ndbs;old_dbnum++)
402-
if (strcmp(old_cluster.dbarr.dbs[old_dbnum].db_name,
403-
new_cluster.dbarr.dbs[new_dbnum].db_name)==0)
404-
break;
405-
if (old_dbnum==old_cluster.dbarr.ndbs)
406-
{
407-
if (strcmp(new_cluster.dbarr.dbs[new_dbnum].db_name,"postgres")==0)
408-
pg_log(PG_FATAL,"The \"postgres\" database must exist in the old cluster\n");
409-
else
410-
pg_log(PG_FATAL,"New cluster database \"%s\" does not exist in the old cluster\n",
411-
new_cluster.dbarr.dbs[new_dbnum].db_name);
412-
}
413-
}
414-
}
415-
416-
417382
/*
418383
* create_script_for_old_cluster_deletion()
419384
*
@@ -462,7 +427,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
462427
fprintf(script,RM_CMD" %s%s/PG_VERSION\n",
463428
os_info.tablespaces[tblnum],old_cluster.tablespace_suffix);
464429

465-
for (dbnum=0;dbnum<new_cluster.dbarr.ndbs;dbnum++)
430+
for (dbnum=0;dbnum<old_cluster.dbarr.ndbs;dbnum++)
466431
{
467432
fprintf(script,RMDIR_CMD" %s%s/%d\n",
468433
os_info.tablespaces[tblnum],old_cluster.tablespace_suffix,

‎contrib/pg_upgrade/function.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ get_loadable_libraries(void)
132132
inttotaltups;
133133
intdbnum;
134134

135-
ress= (PGresult**)
136-
pg_malloc(old_cluster.dbarr.ndbs*sizeof(PGresult*));
135+
ress= (PGresult**)pg_malloc(old_cluster.dbarr.ndbs*sizeof(PGresult*));
137136
totaltups=0;
138137

139138
/* Fetch all library names, removing duplicates within each DB */

‎contrib/pg_upgrade/relfilenode.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,30 @@ const char *
3434
transfer_all_new_dbs(DbInfoArr*old_db_arr,
3535
DbInfoArr*new_db_arr,char*old_pgdata,char*new_pgdata)
3636
{
37-
intdbnum;
37+
intold_dbnum,new_dbnum;
3838
constchar*msg=NULL;
3939

4040
prep_status("Restoring user relation files\n");
4141

42-
if (old_db_arr->ndbs!=new_db_arr->ndbs)
43-
pg_log(PG_FATAL,"old and new clusters have a different number of databases\n");
44-
45-
for (dbnum=0;dbnum<old_db_arr->ndbs;dbnum++)
42+
/* Scan the old cluster databases and transfer their files */
43+
for (old_dbnum=new_dbnum=0;
44+
old_dbnum<old_db_arr->ndbs&&new_dbnum<new_db_arr->ndbs;
45+
old_dbnum++,new_dbnum++)
4646
{
47-
DbInfo*old_db=&old_db_arr->dbs[dbnum];
48-
DbInfo*new_db=&new_db_arr->dbs[dbnum];
47+
DbInfo*old_db=&old_db_arr->dbs[old_dbnum];
48+
DbInfo*new_db=&new_db_arr->dbs[new_dbnum];
4949
FileNameMap*mappings;
5050
intn_maps;
5151
pageCnvCtx*pageConverter=NULL;
5252

53+
/*
54+
*Advance past any databases that exist in the new cluster
55+
*but not in the old, e.g. "postgres".
56+
*/
57+
while (strcmp(old_db->db_name,new_db->db_name)!=0&&
58+
new_dbnum<new_db_arr->ndbs)
59+
new_db=&new_db_arr->dbs[++new_dbnum];
60+
5361
if (strcmp(old_db->db_name,new_db->db_name)!=0)
5462
pg_log(PG_FATAL,"old and new databases have different names: old \"%s\", new \"%s\"\n",
5563
old_db->db_name,new_db->db_name);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp