This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 409d926956770437f6183760c8529170fa4b1a87
Author: Daniel Gustafsson <[email protected]>
AuthorDate: Fri Dec 2 13:10:21 2022 +0100

    Report incompatible roles in pg_upgrade checking
    
    When checking for roles with a pg_ prefix in <= 9.5 servers, report
    all found roles in a text file as how other checks are done instead
    of just reporting that they exist. Rolenames are printed with their
    Oids to match other reports.
    
    Author: Daniel Gustafsson <[email protected]>
    Reviewed-by: Bruce Momjian <[email protected]>
    Reviewed-by: Michael Paquier <[email protected]>
    Discussion: 
https://postgr.es/m/[email protected]
    (cherry picked from commit c76da690ba141160d23cae715922932b7efa5b23)
    
    Cherry-pick diff in gp: use gp_fatal_log function for continuing on
    errors
---
 src/bin/pg_upgrade/check.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index f238796a51..9745f8e0aa 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -1459,27 +1459,52 @@ check_for_pg_role_prefix(ClusterInfo *cluster)
 {
        PGresult   *res;
        PGconn     *conn = connectToServer(cluster, "template1");
+       int                     ntups;
+       int                     i_roloid;
+       int                     i_rolname;
+       FILE       *script = NULL;
+       char            output_path[MAXPGPATH];
 
        prep_status("Checking for roles starting with \"pg_\"");
 
+       snprintf(output_path, sizeof(output_path), "%s/%s",
+                        log_opts.basedir,
+                        "pg_role_prefix.txt");
+
        res = executeQueryOrDie(conn,
-                                                       "SELECT * "
+                                                       "SELECT oid AS roloid, 
rolname "
                                                        "FROM 
pg_catalog.pg_roles "
                                                        "WHERE rolname ~ 
'^pg_'");
 
-       if (PQntuples(res) != 0)
+       ntups = PQntuples(res);
+       i_roloid = PQfnumber(res, "roloid");
+       i_rolname = PQfnumber(res, "rolname");
+       for (int rowno = 0; rowno < ntups; rowno++)
        {
-               if (cluster == &old_cluster)
-                       gp_fatal_log("The source cluster contains roles 
starting with \"pg_\"\n");
-               else
-                       gp_fatal_log("The target cluster contains roles 
starting with \"pg_\"\n");
+               if (script == NULL && (script = fopen_priv(output_path, "w")) 
== NULL)
+                       gp_fatal_log("could not open file \"%s\": %s",
+                                        output_path, strerror(errno));
+               fprintf(script, "%s (oid=%s)\n",
+                               PQgetvalue(res, rowno, i_rolname),
+                               PQgetvalue(res, rowno, i_roloid));
        }
 
        PQclear(res);
 
        PQfinish(conn);
 
-       check_ok();
+       if (script)
+       {
+               fclose(script);
+               pg_log(PG_REPORT, "fatal\n");
+               gp_fatal_log("| Your installation contains roles starting with 
\"pg_\".\n"
+                                "| \"pg_\" is a reserved prefix for system 
roles, the cluster\n"
+                                "| cannot be upgraded until these roles are 
renamed.\n"
+                                "| A list of roles starting with \"pg_\" is in 
the file:\n"
+                                "|     %s", output_path);
+       }
+       else
+               check_ok();
 }
 
 /*


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to