Skip to content

Commit 3d2b6cd

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 cc7091d commit 3d2b6cd

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
@@ -199,6 +199,8 @@ issue_warnings_and_set_wal_level(void)
199199
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906)
200200
old_9_6_invalidate_hash_indexes(&new_cluster, false);
201201

202+
report_extension_updates(&new_cluster);
203+
202204
stop_postmaster(false);
203205
}
204206

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_3_check_for_line_data_type_usage(ClusterInfo *cluster);
454454
void old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster);
455455
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
456456
bool check_mode);
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
@@ -437,3 +437,81 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
437437
else
438438
check_ok();
439439
}
440+
441+
442+
/*
443+
* report_extension_updates()
444+
* Report extensions that should be updated.
445+
*/
446+
void
447+
report_extension_updates(ClusterInfo *cluster)
448+
{
449+
int dbnum;
450+
FILE *script = NULL;
451+
bool found = false;
452+
char *output_path = "update_extensions.sql";
453+
454+
prep_status("Checking for extension updates");
455+
456+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
457+
{
458+
PGresult *res;
459+
bool db_used = false;
460+
int ntups;
461+
int rowno;
462+
int i_name;
463+
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
464+
PGconn *conn = connectToServer(cluster, active_db->db_name);
465+
466+
/* find hash indexes */
467+
res = executeQueryOrDie(conn,
468+
"SELECT name "
469+
"FROM pg_available_extensions "
470+
"WHERE installed_version != default_version"
471+
);
472+
473+
ntups = PQntuples(res);
474+
i_name = PQfnumber(res, "name");
475+
for (rowno = 0; rowno < ntups; rowno++)
476+
{
477+
found = true;
478+
479+
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
480+
pg_fatal("could not open file \"%s\": %s\n", output_path,
481+
strerror(errno));
482+
if (!db_used)
483+
{
484+
PQExpBufferData connectbuf;
485+
486+
initPQExpBuffer(&connectbuf);
487+
appendPsqlMetaConnect(&connectbuf, active_db->db_name);
488+
fputs(connectbuf.data, script);
489+
termPQExpBuffer(&connectbuf);
490+
db_used = true;
491+
}
492+
fprintf(script, "ALTER EXTENSION %s UPDATE;\n",
493+
quote_identifier(PQgetvalue(res, rowno, i_name)));
494+
}
495+
496+
PQclear(res);
497+
498+
PQfinish(conn);
499+
}
500+
501+
if (script)
502+
fclose(script);
503+
504+
if (found)
505+
{
506+
report_status(PG_REPORT, "notice");
507+
pg_log(PG_REPORT, "\n"
508+
"Your installation contains extensions that should be updated\n"
509+
"with the ALTER EXTENSION command. The file\n"
510+
" %s\n"
511+
"when executed by psql by the database superuser will update\n"
512+
"these extensions.\n\n",
513+
output_path);
514+
}
515+
else
516+
check_ok();
517+
}

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