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

Commit2194aa9

Browse files
committed
pg_upgrade: only allow template0 to be non-connectable
This patch causes pg_upgrade to error out during its check phase if:(1) template0 is marked connectableor(2) any other database is marked non-connectableThis is done because, in the first case, pg_upgrade would fail becausethe pg_dumpall --globals restore would fail, and in the second case, thedatabase would not be restored, leading to data loss.Report by Matt Landry (1), Stephen Frost (2)Backpatch through 9.0
1 parent3c3749a commit2194aa9

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ static void set_locale_and_encoding(migratorContext *ctx, Cluster whichCluster);
1414
staticvoidcheck_new_db_is_empty(migratorContext*ctx);
1515
staticvoidcheck_locale_and_encoding(migratorContext*ctx,ControlData*oldctrl,
1616
ControlData*newctrl);
17+
staticvoidcheck_proper_datallowconn(migratorContext*ctx,ClusterwhichCluster);
1718
staticvoidcheck_for_isn_and_int8_passing_mismatch(migratorContext*ctx,
1819
ClusterwhichCluster);
1920
staticvoidcheck_for_reg_data_type_usage(migratorContext*ctx,ClusterwhichCluster);
@@ -94,6 +95,7 @@ check_old_cluster(migratorContext *ctx, bool live_check,
9495
* Check for various failure cases
9596
*/
9697

98+
check_proper_datallowconn(ctx,CLUSTER_OLD);
9799
check_for_reg_data_type_usage(ctx,CLUSTER_OLD);
98100
check_for_isn_and_int8_passing_mismatch(ctx,CLUSTER_OLD);
99101

@@ -485,6 +487,58 @@ create_script_for_old_cluster_deletion(migratorContext *ctx,
485487
}
486488

487489

490+
staticvoid
491+
check_proper_datallowconn(migratorContext*ctx,ClusterwhichCluster)
492+
{
493+
intdbnum;
494+
PGconn*conn_template1;
495+
PGresult*dbres;
496+
intntups;
497+
inti_datname;
498+
inti_datallowconn;
499+
500+
prep_status(ctx,"Checking database connection settings");
501+
502+
conn_template1=connectToServer(ctx,"template1",whichCluster);
503+
504+
/* get database names */
505+
dbres=executeQueryOrDie(ctx,conn_template1,
506+
"SELECTdatname, datallowconn "
507+
"FROMpg_catalog.pg_database");
508+
509+
i_datname=PQfnumber(dbres,"datname");
510+
i_datallowconn=PQfnumber(dbres,"datallowconn");
511+
512+
ntups=PQntuples(dbres);
513+
for (dbnum=0;dbnum<ntups;dbnum++)
514+
{
515+
char*datname=PQgetvalue(dbres,dbnum,i_datname);
516+
char*datallowconn=PQgetvalue(dbres,dbnum,i_datallowconn);
517+
518+
if (strcmp(datname,"template0")==0)
519+
{
520+
/* avoid restore failure when pg_dumpall tries to create template0 */
521+
if (strcmp(datallowconn,"t")==0)
522+
pg_log(ctx,PG_FATAL,"template0 must not allow connections, "
523+
"i.e. its pg_database.datallowconn must be false\n");
524+
}
525+
else
526+
{
527+
/* avoid datallowconn == false databases from being skipped on restore */
528+
if (strcmp(datallowconn,"f")==0)
529+
pg_log(ctx,PG_FATAL,"All non-template0 databases must allow connections, "
530+
"i.e. their pg_database.datallowconn must be true\n");
531+
}
532+
}
533+
534+
PQclear(dbres);
535+
536+
PQfinish(conn_template1);
537+
538+
check_ok(ctx);
539+
}
540+
541+
488542
/*
489543
* check_for_isn_and_int8_passing_mismatch()
490544
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp