mirror of
https://github.com/postgres/postgres.git
synced 2025-07-20 05:03:10 +03:00
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
This commit is contained in:
@ -1395,26 +1395,51 @@ check_for_pg_role_prefix(ClusterInfo *cluster)
|
|||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
PGconn *conn = connectToServer(cluster, "template1");
|
PGconn *conn = connectToServer(cluster, "template1");
|
||||||
|
int ntups;
|
||||||
|
int i_roloid;
|
||||||
|
int i_rolname;
|
||||||
|
FILE *script = NULL;
|
||||||
|
char output_path[MAXPGPATH];
|
||||||
|
|
||||||
prep_status("Checking for roles starting with \"pg_\"");
|
prep_status("Checking for roles starting with \"pg_\"");
|
||||||
|
|
||||||
|
snprintf(output_path, sizeof(output_path), "%s/%s",
|
||||||
|
log_opts.basedir,
|
||||||
|
"pg_role_prefix.txt");
|
||||||
|
|
||||||
res = executeQueryOrDie(conn,
|
res = executeQueryOrDie(conn,
|
||||||
"SELECT * "
|
"SELECT oid AS roloid, rolname "
|
||||||
"FROM pg_catalog.pg_roles "
|
"FROM pg_catalog.pg_roles "
|
||||||
"WHERE rolname ~ '^pg_'");
|
"WHERE rolname ~ '^pg_'");
|
||||||
|
|
||||||
if (PQntuples(res) != 0)
|
ntups = PQntuples(res);
|
||||||
|
i_roloid = PQfnumber(res, "roloid");
|
||||||
|
i_rolname = PQfnumber(res, "rolname");
|
||||||
|
for (int rowno = 0; rowno < ntups; rowno++)
|
||||||
{
|
{
|
||||||
if (cluster == &old_cluster)
|
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
|
||||||
pg_fatal("The source cluster contains roles starting with \"pg_\"");
|
pg_fatal("could not open file \"%s\": %s",
|
||||||
else
|
output_path, strerror(errno));
|
||||||
pg_fatal("The target cluster contains roles starting with \"pg_\"");
|
fprintf(script, "%s (oid=%s)\n",
|
||||||
|
PQgetvalue(res, rowno, i_rolname),
|
||||||
|
PQgetvalue(res, rowno, i_roloid));
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
|
|
||||||
|
if (script)
|
||||||
|
{
|
||||||
|
fclose(script);
|
||||||
|
pg_log(PG_REPORT, "fatal");
|
||||||
|
pg_fatal("Your installation contains roles starting with \"pg_\".\n"
|
||||||
|
"\"pg_\" is a reserved prefix for system roles, the cluster\n"
|
||||||
|
"cannot be upgraded until these roles are renamed.\n"
|
||||||
|
"A list of roles starting with \"pg_\" is in the file:\n"
|
||||||
|
" %s", output_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
check_ok();
|
check_ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user