postgres.git / summary / log / commit / refs

commit    26ebb0e28032283f99bf985fb47ea3d19fbaf91a
Author:   Daniel Gustafsson <dgustafsson@postgresql.org>
Date:     Thu Mar 24 21:41:40 2022 +0000
First released in: 15.0

    List offending databases in pg_upgrade datallowconn check
    
    The check for datallowconn being properly set on all databases in the
    old cluster errored out on the first instance, rather than report the
    set of problematic databases.  This adds reporting to a textfile like
    how many other checks are performed.  While there, also add a comment
    to the function as per how other checks are commented.
    
    This check won't catch if template1 isn't allowing connections, since
    that's used for connecting in the first place.  That error remains as
    it is today:
    
    connection to server on socket ".." failed: FATAL:  database "template1" is not currently accepting connections
    
    Author: Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>
    Reviewed-by: Suraj Kharage <suraj.kharage@enterprisedb.com>
    Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
    Discussion: https://postgr.es/m/CAOgcT0McABqF_iFFQuuRf9is+gmYMsmUu_SWNikyr=2VGyP9Jw@mail.gmail.com


src/bin/pg_upgrade/check.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index cf3b398d9e0..dd3972bb6cf 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -682,6 +682,13 @@ check_is_install_user(ClusterInfo *cluster) } +/* + * check_proper_datallowconn + * + * Ensure that all non-template0 databases allow connections since they + * otherwise won't be restored; and that template0 explicitly doesn't allow + * connections since it would make pg_dumpall --globals restore fail. + */ static void check_proper_datallowconn(ClusterInfo *cluster) { @@ -691,9 +698,16 @@ check_proper_datallowconn(ClusterInfo *cluster) int ntups; int i_datname; int i_datallowconn; + FILE *script = NULL; + char output_path[MAXPGPATH]; + bool found = false; prep_status("Checking database connection settings"); + snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, + "databases_with_datallowconn_false.txt"); + conn_template1 = connectToServer(cluster, "template1"); /* get database names */ @@ -724,8 +738,14 @@ check_proper_datallowconn(ClusterInfo *cluster) * restore */ if (strcmp(datallowconn, "f") == 0) - pg_fatal("All non-template0 databases must allow connections, " - "i.e. their pg_database.datallowconn must be true\n"); + { + found = true; + if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL) + pg_fatal("could not open file \"%s\": %s\n", + output_path, strerror(errno)); + + fprintf(script, "%s\n", datname); + } } } @@ -733,7 +753,22 @@ check_proper_datallowconn(ClusterInfo *cluster) PQfinish(conn_template1); - check_ok(); + if (script) + fclose(script); + + if (found) + { + pg_log(PG_REPORT, "fatal\n"); + pg_fatal("All non-template0 databases must allow connections, i.e. their\n" + "pg_database.datallowconn must be true. Your installation contains\n" + "non-template0 databases with their pg_database.datallowconn set to\n" + "false. Consider allowing connection for all non-template0 databases\n" + "or drop the databases which do not allow connections. A list of\n" + "databases with the problem is in the file:\n" + " %s\n\n", output_path); + } + else + check_ok(); } [parent: ce95c543763b]