Content-Length: 375392 | pFad | http://github.com/postgrespro/postgres/commit/2194aa92b7a65561c109875d8b904198c3cd0743

C6 pg_upgrade: only allow template0 to be non-connectable · postgrespro/postgres@2194aa9 · GitHub
Skip to content

Commit 2194aa9

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 3c3749a commit 2194aa9

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
static void check_new_db_is_empty(migratorContext *ctx);
1515
static void check_locale_and_encoding(migratorContext *ctx, ControlData *oldctrl,
1616
ControlData *newctrl);
17+
static void check_proper_datallowconn(migratorContext *ctx, Cluster whichCluster);
1718
static void check_for_isn_and_int8_passing_mismatch(migratorContext *ctx,
1819
Cluster whichCluster);
1920
static void check_for_reg_data_type_usage(migratorContext *ctx, Cluster whichCluster);
@@ -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+
static void
491+
check_proper_datallowconn(migratorContext *ctx, Cluster whichCluster)
492+
{
493+
int dbnum;
494+
PGconn *conn_template1;
495+
PGresult *dbres;
496+
int ntups;
497+
int i_datname;
498+
int i_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+
"SELECT datname, datallowconn "
507+
"FROM pg_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)








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/2194aa92b7a65561c109875d8b904198c3cd0743

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy