Skip to content

Commit 49e319c

Browse files
committed
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
1 parent ead4ae0 commit 49e319c

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

src/bin/pg_upgrade/check.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ issue_warnings_and_set_wal_level(void)
224224
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906)
225225
old_9_6_invalidate_hash_indexes(&new_cluster, false);
226226

227+
report_extension_updates(&new_cluster);
228+
227229
stop_postmaster(false);
228230
}
229231

src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
466466
bool check_mode);
467467

468468
void old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster);
469+
void report_extension_updates(ClusterInfo *cluster);
469470

470471
/* parallel.c */
471472
void parallel_exec_prog(const char *log_file, const char *opt_log_file,

src/bin/pg_upgrade/version.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,81 @@ old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster)
469469
else
470470
check_ok();
471471
}
472+
473+
474+
/*
475+
* report_extension_updates()
476+
* Report extensions that should be updated.
477+
*/
478+
void
479+
report_extension_updates(ClusterInfo *cluster)
480+
{
481+
int dbnum;
482+
FILE *script = NULL;
483+
bool found = false;
484+
char *output_path = "update_extensions.sql";
485+
486+
prep_status("Checking for extension updates");
487+
488+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
489+
{
490+
PGresult *res;
491+
bool db_used = false;
492+
int ntups;
493+
int rowno;
494+
int i_name;
495+
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
496+
PGconn *conn = connectToServer(cluster, active_db->db_name);
497+
498+
/* find hash indexes */
499+
res = executeQueryOrDie(conn,
500+
"SELECT name "
501+
"FROM pg_available_extensions "
502+
"WHERE installed_version != default_version"
503+
);
504+
505+
ntups = PQntuples(res);
506+
i_name = PQfnumber(res, "name");
507+
for (rowno = 0; rowno < ntups; rowno++)
508+
{
509+
found = true;
510+
511+
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
512+
pg_fatal("could not open file \"%s\": %s\n", output_path,
513+
strerror(errno));
514+
if (!db_used)
515+
{
516+
PQExpBufferData connectbuf;
517+
518+
initPQExpBuffer(&connectbuf);
519+
appendPsqlMetaConnect(&connectbuf, active_db->db_name);
520+
fputs(connectbuf.data, script);
521+
termPQExpBuffer(&connectbuf);
522+
db_used = true;
523+
}
524+
fprintf(script, "ALTER EXTENSION %s UPDATE;\n",
525+
quote_identifier(PQgetvalue(res, rowno, i_name)));
526+
}
527+
528+
PQclear(res);
529+
530+
PQfinish(conn);
531+
}
532+
533+
if (script)
534+
fclose(script);
535+
536+
if (found)
537+
{
538+
report_status(PG_REPORT, "notice");
539+
pg_log(PG_REPORT, "\n"
540+
"Your installation contains extensions that should be updated\n"
541+
"with the ALTER EXTENSION command. The file\n"
542+
" %s\n"
543+
"when executed by psql by the database superuser will update\n"
544+
"these extensions.\n\n",
545+
output_path);
546+
}
547+
else
548+
check_ok();
549+
}

0 commit comments

Comments
 (0)