@@ -1225,6 +1225,39 @@ check_for_prepared_transactions(ClusterInfo *cluster)
1225
1225
check_ok ();
1226
1226
}
1227
1227
1228
+ /*
1229
+ * Callback function for processing result of query for
1230
+ * check_for_isn_and_int8_passing_mismatch()'s UpgradeTask. If the query
1231
+ * returned any rows (i.e., the check failed), write the details to the report
1232
+ * file.
1233
+ */
1234
+ static void
1235
+ process_isn_and_int8_passing_mismatch (DbInfo * dbinfo , PGresult * res , void * arg )
1236
+ {
1237
+ bool db_used = false;
1238
+ int ntups = PQntuples (res );
1239
+ int i_nspname = PQfnumber (res , "nspname" );
1240
+ int i_proname = PQfnumber (res , "proname" );
1241
+ UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1242
+
1243
+ AssertVariableIsOfType (& process_isn_and_int8_passing_mismatch ,
1244
+ UpgradeTaskProcessCB );
1245
+
1246
+ for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1247
+ {
1248
+ if (report -> file == NULL &&
1249
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1250
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1251
+ if (!db_used )
1252
+ {
1253
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1254
+ db_used = true;
1255
+ }
1256
+ fprintf (report -> file , " %s.%s\n" ,
1257
+ PQgetvalue (res , rowno , i_nspname ),
1258
+ PQgetvalue (res , rowno , i_proname ));
1259
+ }
1260
+ }
1228
1261
1229
1262
/*
1230
1263
* check_for_isn_and_int8_passing_mismatch()
@@ -1236,9 +1269,13 @@ check_for_prepared_transactions(ClusterInfo *cluster)
1236
1269
static void
1237
1270
check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster )
1238
1271
{
1239
- int dbnum ;
1240
- FILE * script = NULL ;
1241
- char output_path [MAXPGPATH ];
1272
+ UpgradeTask * task ;
1273
+ UpgradeTaskReport report ;
1274
+ const char * query = "SELECT n.nspname, p.proname "
1275
+ "FROM pg_catalog.pg_proc p, "
1276
+ " pg_catalog.pg_namespace n "
1277
+ "WHERE p.pronamespace = n.oid AND "
1278
+ " p.probin = '$libdir/isn'" ;
1242
1279
1243
1280
prep_status ("Checking for contrib/isn with bigint-passing mismatch" );
1244
1281
@@ -1250,62 +1287,28 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
1250
1287
return ;
1251
1288
}
1252
1289
1253
- snprintf (output_path , sizeof (output_path ), "%s/%s" ,
1290
+ report .file = NULL ;
1291
+ snprintf (report .path , sizeof (report .path ), "%s/%s" ,
1254
1292
log_opts .basedir ,
1255
1293
"contrib_isn_and_int8_pass_by_value.txt" );
1256
1294
1257
- for (dbnum = 0 ; dbnum < cluster -> dbarr .ndbs ; dbnum ++ )
1258
- {
1259
- PGresult * res ;
1260
- bool db_used = false;
1261
- int ntups ;
1262
- int rowno ;
1263
- int i_nspname ,
1264
- i_proname ;
1265
- DbInfo * active_db = & cluster -> dbarr .dbs [dbnum ];
1266
- PGconn * conn = connectToServer (cluster , active_db -> db_name );
1267
-
1268
- /* Find any functions coming from contrib/isn */
1269
- res = executeQueryOrDie (conn ,
1270
- "SELECT n.nspname, p.proname "
1271
- "FROM pg_catalog.pg_proc p, "
1272
- " pg_catalog.pg_namespace n "
1273
- "WHERE p.pronamespace = n.oid AND "
1274
- " p.probin = '$libdir/isn'" );
1275
-
1276
- ntups = PQntuples (res );
1277
- i_nspname = PQfnumber (res , "nspname" );
1278
- i_proname = PQfnumber (res , "proname" );
1279
- for (rowno = 0 ; rowno < ntups ; rowno ++ )
1280
- {
1281
- if (script == NULL && (script = fopen_priv (output_path , "w" )) == NULL )
1282
- pg_fatal ("could not open file \"%s\": %m" , output_path );
1283
- if (!db_used )
1284
- {
1285
- fprintf (script , "In database: %s\n" , active_db -> db_name );
1286
- db_used = true;
1287
- }
1288
- fprintf (script , " %s.%s\n" ,
1289
- PQgetvalue (res , rowno , i_nspname ),
1290
- PQgetvalue (res , rowno , i_proname ));
1291
- }
1292
-
1293
- PQclear (res );
1294
-
1295
- PQfinish (conn );
1296
- }
1295
+ task = upgrade_task_create ();
1296
+ upgrade_task_add_step (task , query , process_isn_and_int8_passing_mismatch ,
1297
+ true, & report );
1298
+ upgrade_task_run (task , cluster );
1299
+ upgrade_task_free (task );
1297
1300
1298
- if (script )
1301
+ if (report . file )
1299
1302
{
1300
- fclose (script );
1303
+ fclose (report . file );
1301
1304
pg_log (PG_REPORT , "fatal" );
1302
1305
pg_fatal ("Your installation contains \"contrib/isn\" functions which rely on the\n"
1303
1306
"bigint data type. Your old and new clusters pass bigint values\n"
1304
1307
"differently so this cluster cannot currently be upgraded. You can\n"
1305
1308
"manually dump databases in the old cluster that use \"contrib/isn\"\n"
1306
1309
"facilities, drop them, perform the upgrade, and then restore them. A\n"
1307
1310
"list of the problem functions is in the file:\n"
1308
- " %s" , output_path );
1311
+ " %s" , report . path );
1309
1312
}
1310
1313
else
1311
1314
check_ok ();
0 commit comments