Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f93f5f7

Browse files
pg_upgrade: Parallelize WITH OIDS check.
This commit makes use of the new task framework in pg_upgrade to parallelize the check for tables declared WITH OIDS. This step will now process multiple databases concurrently when pg_upgrade's --jobs option is provided a value greater than 1. Reviewed-by: Daniel Gustafsson, Ilya Gladyshev Discussion: https://postgr.es/m/20240516211638.GA1688936%40nathanxps13
1 parent cf2f82a commit f93f5f7

File tree

1 file changed

+52
-48
lines changed

1 file changed

+52
-48
lines changed

src/bin/pg_upgrade/check.c

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,72 +1550,76 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster)
15501550
}
15511551

15521552
/*
1553-
* Verify that no tables are declared WITH OIDS.
1553+
* Callback function for processing results of query for
1554+
* check_for_tables_with_oids()'s UpgradeTask. If the query returned any rows
1555+
* (i.e., the check failed), write the details to the report file.
15541556
*/
15551557
static void
1556-
check_for_tables_with_oids(ClusterInfo *cluster)
1558+
process_with_oids_check(DbInfo *dbinfo, PGresult *res, void *arg)
15571559
{
1558-
int dbnum;
1559-
FILE *script = NULL;
1560-
char output_path[MAXPGPATH];
1560+
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
1561+
bool db_used = false;
1562+
int ntups = PQntuples(res);
1563+
int i_nspname = PQfnumber(res, "nspname");
1564+
int i_relname = PQfnumber(res, "relname");
15611565

1562-
prep_status("Checking for tables WITH OIDS");
1566+
AssertVariableIsOfType(&process_with_oids_check, UpgradeTaskProcessCB);
15631567

1564-
snprintf(output_path, sizeof(output_path), "%s/%s",
1565-
log_opts.basedir,
1566-
"tables_with_oids.txt");
1568+
if (!ntups)
1569+
return;
15671570

1568-
/* Find any tables declared WITH OIDS */
1569-
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
1571+
for (int rowno = 0; rowno < ntups; rowno++)
15701572
{
1571-
PGresult *res;
1572-
bool db_used = false;
1573-
int ntups;
1574-
int rowno;
1575-
int i_nspname,
1576-
i_relname;
1577-
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
1578-
PGconn *conn = connectToServer(cluster, active_db->db_name);
1579-
1580-
res = executeQueryOrDie(conn,
1581-
"SELECT n.nspname, c.relname "
1582-
"FROM pg_catalog.pg_class c, "
1583-
" pg_catalog.pg_namespace n "
1584-
"WHERE c.relnamespace = n.oid AND "
1585-
" c.relhasoids AND"
1586-
" n.nspname NOT IN ('pg_catalog')");
1587-
1588-
ntups = PQntuples(res);
1589-
i_nspname = PQfnumber(res, "nspname");
1590-
i_relname = PQfnumber(res, "relname");
1591-
for (rowno = 0; rowno < ntups; rowno++)
1573+
if (report->file == NULL &&
1574+
(report->file = fopen_priv(report->path, "w")) == NULL)
1575+
pg_fatal("could not open file \"%s\": %m", report->path);
1576+
if (!db_used)
15921577
{
1593-
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
1594-
pg_fatal("could not open file \"%s\": %m", output_path);
1595-
if (!db_used)
1596-
{
1597-
fprintf(script, "In database: %s\n", active_db->db_name);
1598-
db_used = true;
1599-
}
1600-
fprintf(script, " %s.%s\n",
1601-
PQgetvalue(res, rowno, i_nspname),
1602-
PQgetvalue(res, rowno, i_relname));
1578+
fprintf(report->file, "In database: %s\n", dbinfo->db_name);
1579+
db_used = true;
16031580
}
1581+
fprintf(report->file, " %s.%s\n",
1582+
PQgetvalue(res, rowno, i_nspname),
1583+
PQgetvalue(res, rowno, i_relname));
1584+
}
1585+
}
16041586

1605-
PQclear(res);
1587+
/*
1588+
* Verify that no tables are declared WITH OIDS.
1589+
*/
1590+
static void
1591+
check_for_tables_with_oids(ClusterInfo *cluster)
1592+
{
1593+
UpgradeTaskReport report;
1594+
UpgradeTask *task = upgrade_task_create();
1595+
const char *query = "SELECT n.nspname, c.relname "
1596+
"FROM pg_catalog.pg_class c, "
1597+
" pg_catalog.pg_namespace n "
1598+
"WHERE c.relnamespace = n.oid AND "
1599+
" c.relhasoids AND"
1600+
" n.nspname NOT IN ('pg_catalog')";
16061601

1607-
PQfinish(conn);
1608-
}
1602+
prep_status("Checking for tables WITH OIDS");
16091603

1610-
if (script)
1604+
report.file = NULL;
1605+
snprintf(report.path, sizeof(report.path), "%s/%s",
1606+
log_opts.basedir,
1607+
"tables_with_oids.txt");
1608+
1609+
upgrade_task_add_step(task, query, process_with_oids_check,
1610+
true, &report);
1611+
upgrade_task_run(task, cluster);
1612+
upgrade_task_free(task);
1613+
1614+
if (report.file)
16111615
{
1612-
fclose(script);
1616+
fclose(report.file);
16131617
pg_log(PG_REPORT, "fatal");
16141618
pg_fatal("Your installation contains tables declared WITH OIDS, which is not\n"
16151619
"supported anymore. Consider removing the oid column using\n"
16161620
" ALTER TABLE ... SET WITHOUT OIDS;\n"
16171621
"A list of tables with the problem is in the file:\n"
1618-
" %s", output_path);
1622+
" %s", report.path);
16191623
}
16201624
else
16211625
check_ok();

0 commit comments

Comments
 (0)