@@ -437,3 +437,81 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
437
437
else
438
438
check_ok ();
439
439
}
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