Content-Length: 374830 | pFad | http://github.com/postgrespro/postgres/commit/321db71239cb45ed2f2d3113ff5745757a64581a

5C pg_upgrade: only allow template0 to be non-connectable · postgrespro/postgres@321db71 · GitHub
Skip to content

Commit 321db71

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 connectable or (2) any other database is marked non-connectable This is done because, in the first case, pg_upgrade would fail because the pg_dumpall --globals restore would fail, and in the second case, the database would not be restored, leading to data loss. Report by Matt Landry (1), Stephen Frost (2) Backpatch through 9.0
1 parent 436f356 commit 321db71

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
static void check_locale_and_encoding(ControlData *oldctrl,
1717
ControlData *newctrl);
1818
static void check_is_super_user(ClusterInfo *cluster);
19+
static void check_proper_datallowconn(ClusterInfo *cluster);
1920
static void check_for_prepared_transactions(ClusterInfo *cluster);
2021
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
2122
static void check_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+
static void
586+
check_proper_datallowconn(ClusterInfo *cluster)
587+
{
588+
int dbnum;
589+
PGconn *conn_template1;
590+
PGresult *dbres;
591+
int ntups;
592+
int i_datname;
593+
int i_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+
"SELECT datname, datallowconn "
602+
"FROM pg_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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/321db71239cb45ed2f2d3113ff5745757a64581a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy