@@ -469,3 +469,81 @@ old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster)
469
469
else
470
470
check_ok ();
471
471
}
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