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