dump_user_config_last_with_set_role.patch
text/x-patch
Filename: dump_user_config_last_with_set_role.patch
Type: text/x-patch
Part: 0
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c new file mode 100644 index b5f64e8..7f2b03e *** a/src/bin/pg_dump/pg_dumpall.c --- b/src/bin/pg_dump/pg_dumpall.c *************** static int server_version; *** 79,84 **** --- 79,85 ---- static FILE *OPF; static char *filename = NULL; + static char *use_role = NULL; int main(int argc, char *argv[]) *************** main(int argc, char *argv[]) *** 87,93 **** char *pgport = NULL; char *pguser = NULL; char *pgdb = NULL; - char *use_role = NULL; enum trivalue prompt_password = TRI_DEFAULT; bool data_only = false; bool globals_only = false; --- 88,93 ---- *************** main(int argc, char *argv[]) *** 443,448 **** --- 443,452 ---- fprintf(OPF, "\\connect postgres\n\n"); + if (use_role && server_version >= 80100) + fprintf(OPF, "SET ROLE %s;\n", + fmtId(use_role)); + /* Replicate encoding and std_strings in output */ fprintf(OPF, "SET client_encoding = '%s';\n", pg_encoding_to_char(encoding)); *************** dumpRoles(PGconn *conn) *** 804,814 **** buf, "ROLE", rolename); fprintf(OPF, "%s", buf->data); - - if (server_version >= 70300) - dumpUserConfig(conn, rolename); } PQclear(res); fprintf(OPF, "\n\n"); --- 808,819 ---- buf, "ROLE", rolename); fprintf(OPF, "%s", buf->data); } + if (server_version >= 70300) + for (i = 0; i < PQntuples(res); i++) + dumpUserConfig(conn, PQgetvalue(res, i, i_rolname)); + PQclear(res); fprintf(OPF, "\n\n"); *************** dumpDatabases(PGconn *conn) *** 1561,1566 **** --- 1566,1575 ---- fprintf(OPF, "\\connect %s\n\n", fmtId(dbname)); + if (use_role && server_version >= 80100) + fprintf(OPF, "SET ROLE %s;\n\n", + fmtId(use_role)); + if (filename) fclose(OPF);