@@ -139,72 +139,76 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
139
139
check_ok ();
140
140
}
141
141
142
+ /*
143
+ * Callback function for processing results of query for
144
+ * report_extension_updates()'s UpgradeTask. If the query returned any rows,
145
+ * write the details to the report file.
146
+ */
147
+ static void
148
+ process_extension_updates (DbInfo * dbinfo , PGresult * res , void * arg )
149
+ {
150
+ bool db_used = false;
151
+ int ntups = PQntuples (res );
152
+ int i_name = PQfnumber (res , "name" );
153
+ UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
154
+
155
+ AssertVariableIsOfType (& process_extension_updates , UpgradeTaskProcessCB );
156
+
157
+ for (int rowno = 0 ; rowno < ntups ; rowno ++ )
158
+ {
159
+ if (report -> file == NULL &&
160
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
161
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
162
+ if (!db_used )
163
+ {
164
+ PQExpBufferData connectbuf ;
165
+
166
+ initPQExpBuffer (& connectbuf );
167
+ appendPsqlMetaConnect (& connectbuf , dbinfo -> db_name );
168
+ fputs (connectbuf .data , report -> file );
169
+ termPQExpBuffer (& connectbuf );
170
+ db_used = true;
171
+ }
172
+ fprintf (report -> file , "ALTER EXTENSION %s UPDATE;\n" ,
173
+ quote_identifier (PQgetvalue (res , rowno , i_name )));
174
+ }
175
+ }
176
+
142
177
/*
143
178
* report_extension_updates()
144
179
* Report extensions that should be updated.
145
180
*/
146
181
void
147
182
report_extension_updates (ClusterInfo * cluster )
148
183
{
149
- int dbnum ;
150
- FILE * script = NULL ;
151
- char * output_path = "update_extensions.sql" ;
184
+ UpgradeTaskReport report ;
185
+ UpgradeTask * task = upgrade_task_create ();
186
+ const char * query = "SELECT name "
187
+ "FROM pg_available_extensions "
188
+ "WHERE installed_version != default_version" ;
152
189
153
190
prep_status ("Checking for extension updates" );
154
191
155
- for (dbnum = 0 ; dbnum < cluster -> dbarr .ndbs ; dbnum ++ )
156
- {
157
- PGresult * res ;
158
- bool db_used = false;
159
- int ntups ;
160
- int rowno ;
161
- int i_name ;
162
- DbInfo * active_db = & cluster -> dbarr .dbs [dbnum ];
163
- PGconn * conn = connectToServer (cluster , active_db -> db_name );
164
-
165
- /* find extensions needing updates */
166
- res = executeQueryOrDie (conn ,
167
- "SELECT name "
168
- "FROM pg_available_extensions "
169
- "WHERE installed_version != default_version"
170
- );
192
+ report .file = NULL ;
193
+ strcpy (report .path , "update_extensions.sql" );
171
194
172
- ntups = PQntuples (res );
173
- i_name = PQfnumber (res , "name" );
174
- for (rowno = 0 ; rowno < ntups ; rowno ++ )
175
- {
176
- if (script == NULL && (script = fopen_priv (output_path , "w" )) == NULL )
177
- pg_fatal ("could not open file \"%s\": %m" , output_path );
178
- if (!db_used )
179
- {
180
- PQExpBufferData connectbuf ;
195
+ upgrade_task_add_step (task , query , process_extension_updates ,
196
+ true, & report );
181
197
182
- initPQExpBuffer (& connectbuf );
183
- appendPsqlMetaConnect (& connectbuf , active_db -> db_name );
184
- fputs (connectbuf .data , script );
185
- termPQExpBuffer (& connectbuf );
186
- db_used = true;
187
- }
188
- fprintf (script , "ALTER EXTENSION %s UPDATE;\n" ,
189
- quote_identifier (PQgetvalue (res , rowno , i_name )));
190
- }
198
+ upgrade_task_run (task , cluster );
199
+ upgrade_task_free (task );
191
200
192
- PQclear (res );
193
-
194
- PQfinish (conn );
195
- }
196
-
197
- if (script )
201
+ if (report .file )
198
202
{
199
- fclose (script );
203
+ fclose (report . file );
200
204
report_status (PG_REPORT , "notice" );
201
205
pg_log (PG_REPORT , "\n"
202
206
"Your installation contains extensions that should be updated\n"
203
207
"with the ALTER EXTENSION command. The file\n"
204
208
" %s\n"
205
209
"when executed by psql by the database superuser will update\n"
206
210
"these extensions." ,
207
- output_path );
211
+ report . path );
208
212
}
209
213
else
210
214
check_ok ();
0 commit comments