diff options
author | Bruce Momjian | 2021-08-03 15:58:15 +0000 |
---|---|---|
committer | Bruce Momjian | 2021-08-03 15:58:15 +0000 |
commit | e462856a7a559c94bad51507c6b324f337d8254b (patch) | |
tree | abf4c766b7b4fee7a9384664054702bcf2cfa5f6 /src/bin/pg_upgrade/version.c | |
parent | 5090d709f172ecd00b16b6e336c8c149a3f3d33d (diff) |
pg_upgrade: warn about extensions that need updating
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
Diffstat (limited to 'src/bin/pg_upgrade/version.c')
-rw-r--r-- | src/bin/pg_upgrade/version.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/bin/pg_upgrade/version.c b/src/bin/pg_upgrade/version.c index a3c193316d0..b82afafd22d 100644 --- a/src/bin/pg_upgrade/version.c +++ b/src/bin/pg_upgrade/version.c @@ -468,3 +468,81 @@ old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster) 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(); +} |