{
PGresult *res;
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_\"");
+ snprintf(output_path, sizeof(output_path), "%s/%s",
+ log_opts.basedir,
+ "pg_role_prefix.txt");
+
res = executeQueryOrDie(conn,
- "SELECT * "
+ "SELECT oid AS roloid, rolname "
"FROM pg_catalog.pg_roles "
"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)
- pg_fatal("The source cluster contains roles starting with \"pg_\"");
- else
- pg_fatal("The target cluster contains roles starting with \"pg_\"");
+ if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %s",
+ output_path, strerror(errno));
+ fprintf(script, "%s (oid=%s)\n",
+ PQgetvalue(res, rowno, i_rolname),
+ PQgetvalue(res, rowno, i_roloid));
}
PQclear(res);
PQfinish(conn);
- check_ok();
+ 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();
}
/*