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

Commit321db71

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 parent436f356 commit321db71

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
@@ -16,6 +16,7 @@ static void check_old_cluster_has_new_cluster_dbs(void);
1616
staticvoidcheck_locale_and_encoding(ControlData*oldctrl,
1717
ControlData*newctrl);
1818
staticvoidcheck_is_super_user(ClusterInfo*cluster);
19+
staticvoidcheck_proper_datallowconn(ClusterInfo*cluster);
1920
staticvoidcheck_for_prepared_transactions(ClusterInfo*cluster);
2021
staticvoidcheck_for_isn_and_int8_passing_mismatch(ClusterInfo*cluster);
2122
staticvoidcheck_for_reg_data_type_usage(ClusterInfo*cluster);
@@ -97,6 +98,7 @@ check_old_cluster(bool live_check,
9798
* Check for various failure cases
9899
*/
99100
check_is_super_user(&old_cluster);
101+
check_proper_datallowconn(&old_cluster);
100102
check_for_prepared_transactions(&old_cluster);
101103
check_for_reg_data_type_usage(&old_cluster);
102104
check_for_isn_and_int8_passing_mismatch(&old_cluster);
@@ -580,6 +582,58 @@ check_is_super_user(ClusterInfo *cluster)
580582
}
581583

582584

585+
staticvoid
586+
check_proper_datallowconn(ClusterInfo*cluster)
587+
{
588+
intdbnum;
589+
PGconn*conn_template1;
590+
PGresult*dbres;
591+
intntups;
592+
inti_datname;
593+
inti_datallowconn;
594+
595+
prep_status("Checking database connection settings");
596+
597+
conn_template1=connectToServer(cluster,"template1");
598+
599+
/* get database names */
600+
dbres=executeQueryOrDie(conn_template1,
601+
"SELECTdatname, datallowconn "
602+
"FROMpg_catalog.pg_database");
603+
604+
i_datname=PQfnumber(dbres,"datname");
605+
i_datallowconn=PQfnumber(dbres,"datallowconn");
606+
607+
ntups=PQntuples(dbres);
608+
for (dbnum=0;dbnum<ntups;dbnum++)
609+
{
610+
char*datname=PQgetvalue(dbres,dbnum,i_datname);
611+
char*datallowconn=PQgetvalue(dbres,dbnum,i_datallowconn);
612+
613+
if (strcmp(datname,"template0")==0)
614+
{
615+
/* avoid restore failure when pg_dumpall tries to create template0 */
616+
if (strcmp(datallowconn,"t")==0)
617+
pg_log(PG_FATAL,"template0 must not allow connections, "
618+
"i.e. its pg_database.datallowconn must be false\n");
619+
}
620+
else
621+
{
622+
/* avoid datallowconn == false databases from being skipped on restore */
623+
if (strcmp(datallowconn,"f")==0)
624+
pg_log(PG_FATAL,"All non-template0 databases must allow connections, "
625+
"i.e. their pg_database.datallowconn must be true\n");
626+
}
627+
}
628+
629+
PQclear(dbres);
630+
631+
PQfinish(conn_template1);
632+
633+
check_ok();
634+
}
635+
636+
583637
/*
584638
*check_for_prepared_transactions()
585639
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp