@ -139,6 +139,41 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
check_ok ( ) ;
check_ok ( ) ;
}
}
/*
* Callback function for processing results of query for
* report_extension_updates ( ) ' s UpgradeTask . If the query returned any rows ,
* write the details to the report file .
*/
static void
process_extension_updates ( DbInfo * dbinfo , PGresult * res , void * arg )
{
bool db_used = false ;
int ntups = PQntuples ( res ) ;
int i_name = PQfnumber ( res , " name " ) ;
UpgradeTaskReport * report = ( UpgradeTaskReport * ) arg ;
AssertVariableIsOfType ( & process_extension_updates , UpgradeTaskProcessCB ) ;
for ( int rowno = 0 ; rowno < ntups ; rowno + + )
{
if ( report - > file = = NULL & &
( report - > file = fopen_priv ( report - > path , " w " ) ) = = NULL )
pg_fatal ( " could not open file \" %s \" : %m " , report - > path ) ;
if ( ! db_used )
{
PQExpBufferData connectbuf ;
initPQExpBuffer ( & connectbuf ) ;
appendPsqlMetaConnect ( & connectbuf , dbinfo - > db_name ) ;
fputs ( connectbuf . data , report - > file ) ;
termPQExpBuffer ( & connectbuf ) ;
db_used = true ;
}
fprintf ( report - > file , " ALTER EXTENSION %s UPDATE; \n " ,
quote_identifier ( PQgetvalue ( res , rowno , i_name ) ) ) ;
}
}
/*
/*
* report_extension_updates ( )
* report_extension_updates ( )
* Report extensions that should be updated .
* Report extensions that should be updated .
@ -146,57 +181,26 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
void
void
report_extension_updates ( ClusterInfo * cluster )
report_extension_updates ( ClusterInfo * cluster )
{
{
int dbnum ;
UpgradeTaskReport report ;
FILE * script = NULL ;
UpgradeTask * task = upgrade_task_create ( ) ;
char * output_path = " update_extensions.sql " ;
const char * query = " SELECT name "
" FROM pg_available_extensions "
" WHERE installed_version != default_version " ;
prep_status ( " Checking for extension updates " ) ;
prep_status ( " Checking for extension updates " ) ;
for ( dbnum = 0 ; dbnum < cluster - > dbarr . ndbs ; dbnum + + )
report . file = NULL ;
{
strcpy ( report . path , " update_extensions.sql " ) ;
PGresult * res ;
bool db_used = false ;
int ntups ;
int rowno ;
int i_name ;
DbInfo * active_db = & cluster - > dbarr . dbs [ dbnum ] ;
PGconn * conn = connectToServer ( cluster , active_db - > db_name ) ;
/* find extensions needing updates */
res = executeQueryOrDie ( conn ,
" SELECT name "
" FROM pg_available_extensions "
" WHERE installed_version != default_version "
) ;
ntups = PQntuples ( res ) ;
upgrade_task_add_step ( task , query , process_extension_updates ,
i_name = PQfnumber ( res , " name " ) ;
true , & report ) ;
for ( rowno = 0 ; rowno < ntups ; rowno + + )
{
if ( script = = NULL & & ( script = fopen_priv ( output_path , " w " ) ) = = NULL )
pg_fatal ( " could not open file \" %s \" : %m " , output_path ) ;
if ( ! db_used )
{
PQExpBufferData connectbuf ;
initPQExpBuffer ( & connectbuf ) ;
upgrade_task_run ( task , cluster ) ;
appendPsqlMetaConnect ( & connectbuf , active_db - > db_name ) ;
upgrade_task_free ( task ) ;
fputs ( connectbuf . data , script ) ;
termPQExpBuffer ( & connectbuf ) ;
db_used = true ;
}
fprintf ( script , " ALTER EXTENSION %s UPDATE; \n " ,
quote_identifier ( PQgetvalue ( res , rowno , i_name ) ) ) ;
}
PQclear ( res ) ;
if ( report . file )
PQfinish ( conn ) ;
}
if ( script )
{
{
fclose ( script ) ;
fclose ( report . file ) ;
report_status ( PG_REPORT , " notice " ) ;
report_status ( PG_REPORT , " notice " ) ;
pg_log ( PG_REPORT , " \n "
pg_log ( PG_REPORT , " \n "
" Your installation contains extensions that should be updated \n "
" Your installation contains extensions that should be updated \n "
@ -204,7 +208,7 @@ report_extension_updates(ClusterInfo *cluster)
" %s \n "
" %s \n "
" when executed by psql by the database superuser will update \n "
" when executed by psql by the database superuser will update \n "
" these extensions. " ,
" these extensions. " ,
output_ path) ;
report . path ) ;
}
}
else
else
check_ok ( ) ;
check_ok ( ) ;