]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pg_upgrade: warn about extensions that need updating
authorBruce Momjian <bruce@momjian.us>
Tue, 3 Aug 2021 15:58:14 +0000 (11:58 -0400)
committerBruce Momjian <bruce@momjian.us>
Tue, 3 Aug 2021 15:58:14 +0000 (11:58 -0400)
Also create a script that can be run to update them.

Reported-by: Dave Cramer
Discussion: https://postgr.es/m/CADK3HHKawwbOcGwMGnDuAf3-U8YfvTcS8jqDv3UM=niijs3MMA@mail.gmail.com

Backpatch-through: 9.6

src/bin/pg_upgrade/check.c
src/bin/pg_upgrade/pg_upgrade.h
src/bin/pg_upgrade/version.c

index fbf541712e2f5e916c18a6c687edb74260af7f55..012b0111bb6fbd6f21e372aec1aa02948c0c31f8 100644 (file)
@@ -199,6 +199,8 @@ issue_warnings_and_set_wal_level(void)
        if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906)
                old_9_6_invalidate_hash_indexes(&new_cluster, false);
 
+       report_extension_updates(&new_cluster);
+
        stop_postmaster(false);
 }
 
index 1a7cbbbf51f0867bb566c2c535e85bde289ae8d3..6e23fd5f98323fa31fc6d88e05747cc05c6687ba 100644 (file)
@@ -454,6 +454,7 @@ void                old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
 void           old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster);
 void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
                                                                bool check_mode);
+void           report_extension_updates(ClusterInfo *cluster);
 
 /* parallel.c */
 void parallel_exec_prog(const char *log_file, const char *opt_log_file,
index 0b0af78ca7810757546a659664cc407fe5652899..8330d5656c7c4e588f5ff078642496b2c5a7751d 100644 (file)
@@ -437,3 +437,81 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
        else
                check_ok();
 }
+
+
+/*
+ * report_extension_updates()
+ *     Report extensions that should be updated.
+ */
+void
+report_extension_updates(ClusterInfo *cluster)
+{
+       int                     dbnum;
+       FILE       *script = NULL;
+       bool            found = false;
+       char       *output_path = "update_extensions.sql";
+
+       prep_status("Checking for extension updates");
+
+       for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
+       {
+               PGresult   *res;
+               bool            db_used = false;
+               int                     ntups;
+               int                     rowno;
+               int                     i_name;
+               DbInfo     *active_db = &cluster->dbarr.dbs[dbnum];
+               PGconn     *conn = connectToServer(cluster, active_db->db_name);
+
+               /* find hash indexes */
+               res = executeQueryOrDie(conn,
+                                                               "SELECT name "
+                                                               "FROM pg_available_extensions "
+                                                               "WHERE installed_version != default_version"
+                       );
+
+               ntups = PQntuples(res);
+               i_name = PQfnumber(res, "name");
+               for (rowno = 0; rowno < ntups; rowno++)
+               {
+                       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));
+                       if (!db_used)
+                       {
+                               PQExpBufferData connectbuf;
+
+                               initPQExpBuffer(&connectbuf);
+                               appendPsqlMetaConnect(&connectbuf, active_db->db_name);
+                               fputs(connectbuf.data, script);
+                               termPQExpBuffer(&connectbuf);
+                               db_used = true;
+                       }
+                       fprintf(script, "ALTER EXTENSION %s UPDATE;\n",
+                                       quote_identifier(PQgetvalue(res, rowno, i_name)));
+               }
+
+               PQclear(res);
+
+               PQfinish(conn);
+       }
+
+       if (script)
+               fclose(script);
+
+       if (found)
+       {
+               report_status(PG_REPORT, "notice");
+               pg_log(PG_REPORT, "\n"
+                          "Your installation contains extensions that should be updated\n"
+                          "with the ALTER EXTENSION command.  The file\n"
+                          "    %s\n"
+                          "when executed by psql by the database superuser will update\n"
+                          "these extensions.\n\n",
+                          output_path);
+       }
+       else
+               check_ok();
+}