Skip to content

Commit c76da69

Browse files
Report incompatible roles in pg_upgrade checking
When checking for roles with a pg_ prefix in <= 9.5 servers, report all found roles in a text file as how other checks are done instead of just reporting that they exist. Rolenames are printed with their Oids to match other reports. Author: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Bruce Momjian <bruce@momjian.us> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/4BB2735C-C347-4CF7-AFB1-8573BE930066@yesql.se
1 parent ab81006 commit c76da69

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/bin/pg_upgrade/check.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,27 +1395,52 @@ check_for_pg_role_prefix(ClusterInfo *cluster)
13951395
{
13961396
PGresult *res;
13971397
PGconn *conn = connectToServer(cluster, "template1");
1398+
int ntups;
1399+
int i_roloid;
1400+
int i_rolname;
1401+
FILE *script = NULL;
1402+
char output_path[MAXPGPATH];
13981403

13991404
prep_status("Checking for roles starting with \"pg_\"");
14001405

1406+
snprintf(output_path, sizeof(output_path), "%s/%s",
1407+
log_opts.basedir,
1408+
"pg_role_prefix.txt");
1409+
14011410
res = executeQueryOrDie(conn,
1402-
"SELECT * "
1411+
"SELECT oid AS roloid, rolname "
14031412
"FROM pg_catalog.pg_roles "
14041413
"WHERE rolname ~ '^pg_'");
14051414

1406-
if (PQntuples(res) != 0)
1415+
ntups = PQntuples(res);
1416+
i_roloid = PQfnumber(res, "roloid");
1417+
i_rolname = PQfnumber(res, "rolname");
1418+
for (int rowno = 0; rowno < ntups; rowno++)
14071419
{
1408-
if (cluster == &old_cluster)
1409-
pg_fatal("The source cluster contains roles starting with \"pg_\"");
1410-
else
1411-
pg_fatal("The target cluster contains roles starting with \"pg_\"");
1420+
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
1421+
pg_fatal("could not open file \"%s\": %s",
1422+
output_path, strerror(errno));
1423+
fprintf(script, "%s (oid=%s)\n",
1424+
PQgetvalue(res, rowno, i_rolname),
1425+
PQgetvalue(res, rowno, i_roloid));
14121426
}
14131427

14141428
PQclear(res);
14151429

14161430
PQfinish(conn);
14171431

1418-
check_ok();
1432+
if (script)
1433+
{
1434+
fclose(script);
1435+
pg_log(PG_REPORT, "fatal");
1436+
pg_fatal("Your installation contains roles starting with \"pg_\".\n"
1437+
"\"pg_\" is a reserved prefix for system roles, the cluster\n"
1438+
"cannot be upgraded until these roles are renamed.\n"
1439+
"A list of roles starting with \"pg_\" is in the file:\n"
1440+
" %s", output_path);
1441+
}
1442+
else
1443+
check_ok();
14191444
}
14201445

14211446
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy