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 106062292d8fee49cb68c8460d89aeb5e08662b8
Author: Marbin Tan <[email protected]>
AuthorDate: Thu Mar 14 11:37:07 2024 -0700

    pg_upgrade: Add check for disallowed OPERATOR
    
    For 9.5 and beyond, doing `CREATE OPERATOR =>` has been removed and
    disallowed. The => operator is now reserved for named parameters. As a
    result, any user defined operations that are => cannot be upgraded.
    
    With this commit, a check has been added to ensure that the source
    cluster is compatable with the target cluster.
    
    The upstream change happened in commit 
865f14a2d31af23a05bbf2df04c274629c5d5c4d.
---
 src/bin/pg_upgrade/greenplum/check_gp.c | 66 +++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/bin/pg_upgrade/greenplum/check_gp.c 
b/src/bin/pg_upgrade/greenplum/check_gp.c
index aae2c3bd70..b724051a23 100644
--- a/src/bin/pg_upgrade/greenplum/check_gp.c
+++ b/src/bin/pg_upgrade/greenplum/check_gp.c
@@ -30,6 +30,7 @@ static void 
check_for_plpython2_dependent_functions(ClusterInfo *cluster);
 static void check_views_with_removed_operators(void);
 static void check_views_with_removed_functions(void);
 static void check_views_with_removed_types(void);
+static void check_for_disallowed_pg_operator(void);
 
 /*
  *     check_greenplum
@@ -53,6 +54,7 @@ check_greenplum(void)
        check_views_with_removed_operators();
        check_views_with_removed_functions();
        check_views_with_removed_types();
+       check_for_disallowed_pg_operator();
 }
 
 /*
@@ -1091,3 +1093,67 @@ check_views_with_removed_types()
        else
                check_ok();
 }
+
+/*
+ * check_for_disallowed_pg_operator(void)
+ *
+ * Versions greater than 9.4 disallows `CREATE OPERATOR =>`
+ */
+static void
+check_for_disallowed_pg_operator(void)
+{
+       int                     dbnum;
+       char            output_path[MAXPGPATH];
+       bool            found = false;
+       FILE            *script = NULL;
+
+       if (GET_MAJOR_VERSION(old_cluster.major_version) > 904)
+               return;
+
+       prep_status("Checking for disallowed OPERATOR =>");
+
+       snprintf(output_path, sizeof(output_path), "%s/%s",
+                        log_opts.basedir,
+                        "databases_with_disallowed_pg_operator.txt");
+
+       for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
+       {
+               PGresult   *res;
+               DbInfo     *active_db = &old_cluster.dbarr.dbs[dbnum];
+               PGconn     *conn = connectToServer(&old_cluster, 
active_db->db_name);
+
+               /* Find any disallowed operator '=>' in all the databases */
+               res = executeQueryOrDie(conn,
+                                                               "SELECT * "
+                                                               "FROM 
pg_operator "
+                                                               "WHERE oprname 
= '=>' AND "
+                                                               "          oid 
>= 16384");
+
+               if (PQntuples(res) != 0)
+               {
+                       found = true;
+                       if (script == NULL && (script = fopen(output_path, 
"w")) == NULL)
+                               pg_fatal("Could not create necessary file:  
%s\n", output_path);
+
+                       fprintf(script, "%s\n", active_db->db_name);
+               }
+
+               PQclear(res);
+               PQfinish(conn);
+       }
+
+       if (script)
+               fclose(script);
+
+       if (found)
+       {
+               pg_log(PG_REPORT, "fatal\n");
+               gp_fatal_log(
+                                        "| Your installation contains 
disallowed OPERATOR =>.\n"
+                                        "| You will need to remove the 
disallowed OPERATOR =>\n"
+                                        "| from the list of databases in the 
file:\n"
+                                        "|    %s\n\n", output_path);
+       }
+       else
+               check_ok();
+}


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

Reply via email to