Skip to content

Commit 4051a77

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 9f6215b commit 4051a77

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
@@ -241,6 +241,8 @@ issue_warnings_and_set_wal_level(void)
241241
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906)
242242
old_9_6_invalidate_hash_indexes(&new_cluster, false);
243243

244+
report_extension_updates(&new_cluster);
245+
244246
stop_postmaster(false);
245247
}
246248

src/bin/pg_upgrade/pg_upgrade.h

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

456456
void old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster);
457+
void report_extension_updates(ClusterInfo *cluster);
457458

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy