Commit db00d837 authored by Bruce Momjian's avatar Bruce Momjian

In pg_upgrade, fix bug where no users were dumped in pg_dumpall

binary-upgrade mode;  instead only skip dumping the current user.

This bug was introduced in during the removal of split_old_dump().  Bug
discovered during local testing.
parent 7510bec6
...@@ -642,7 +642,8 @@ dumpRoles(PGconn *conn) ...@@ -642,7 +642,8 @@ dumpRoles(PGconn *conn)
i_rolpassword, i_rolpassword,
i_rolvaliduntil, i_rolvaliduntil,
i_rolreplication, i_rolreplication,
i_rolcomment; i_rolcomment,
i_is_current_user;
int i; int i;
/* note: rolconfig is dumped later */ /* note: rolconfig is dumped later */
...@@ -652,7 +653,8 @@ dumpRoles(PGconn *conn) ...@@ -652,7 +653,8 @@ dumpRoles(PGconn *conn)
"rolcreaterole, rolcreatedb, " "rolcreaterole, rolcreatedb, "
"rolcanlogin, rolconnlimit, rolpassword, " "rolcanlogin, rolconnlimit, rolpassword, "
"rolvaliduntil, rolreplication, " "rolvaliduntil, rolreplication, "
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment " "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
"rolname = current_user AS is_current_user "
"FROM pg_authid " "FROM pg_authid "
"ORDER BY 2"); "ORDER BY 2");
else if (server_version >= 80200) else if (server_version >= 80200)
...@@ -661,7 +663,8 @@ dumpRoles(PGconn *conn) ...@@ -661,7 +663,8 @@ dumpRoles(PGconn *conn)
"rolcreaterole, rolcreatedb, " "rolcreaterole, rolcreatedb, "
"rolcanlogin, rolconnlimit, rolpassword, " "rolcanlogin, rolconnlimit, rolpassword, "
"rolvaliduntil, false as rolreplication, " "rolvaliduntil, false as rolreplication, "
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment " "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
"rolname = current_user AS is_current_user "
"FROM pg_authid " "FROM pg_authid "
"ORDER BY 2"); "ORDER BY 2");
else if (server_version >= 80100) else if (server_version >= 80100)
...@@ -670,7 +673,8 @@ dumpRoles(PGconn *conn) ...@@ -670,7 +673,8 @@ dumpRoles(PGconn *conn)
"rolcreaterole, rolcreatedb, " "rolcreaterole, rolcreatedb, "
"rolcanlogin, rolconnlimit, rolpassword, " "rolcanlogin, rolconnlimit, rolpassword, "
"rolvaliduntil, false as rolreplication, " "rolvaliduntil, false as rolreplication, "
"null as rolcomment " "null as rolcomment, "
"rolname = current_user AS is_current_user "
"FROM pg_authid " "FROM pg_authid "
"ORDER BY 2"); "ORDER BY 2");
else else
...@@ -685,7 +689,8 @@ dumpRoles(PGconn *conn) ...@@ -685,7 +689,8 @@ dumpRoles(PGconn *conn)
"passwd as rolpassword, " "passwd as rolpassword, "
"valuntil as rolvaliduntil, " "valuntil as rolvaliduntil, "
"false as rolreplication, " "false as rolreplication, "
"null as rolcomment " "null as rolcomment, "
"rolname = current_user AS is_current_user "
"FROM pg_shadow " "FROM pg_shadow "
"UNION ALL " "UNION ALL "
"SELECT 0, groname as rolname, " "SELECT 0, groname as rolname, "
...@@ -698,7 +703,7 @@ dumpRoles(PGconn *conn) ...@@ -698,7 +703,7 @@ dumpRoles(PGconn *conn)
"null::text as rolpassword, " "null::text as rolpassword, "
"null::abstime as rolvaliduntil, " "null::abstime as rolvaliduntil, "
"false as rolreplication, " "false as rolreplication, "
"null as rolcomment " "null as rolcomment, false "
"FROM pg_group " "FROM pg_group "
"WHERE NOT EXISTS (SELECT 1 FROM pg_shadow " "WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
" WHERE usename = groname) " " WHERE usename = groname) "
...@@ -718,6 +723,7 @@ dumpRoles(PGconn *conn) ...@@ -718,6 +723,7 @@ dumpRoles(PGconn *conn)
i_rolvaliduntil = PQfnumber(res, "rolvaliduntil"); i_rolvaliduntil = PQfnumber(res, "rolvaliduntil");
i_rolreplication = PQfnumber(res, "rolreplication"); i_rolreplication = PQfnumber(res, "rolreplication");
i_rolcomment = PQfnumber(res, "rolcomment"); i_rolcomment = PQfnumber(res, "rolcomment");
i_is_current_user = PQfnumber(res, "is_current_user");
if (PQntuples(res) > 0) if (PQntuples(res) > 0)
fprintf(OPF, "--\n-- Roles\n--\n\n"); fprintf(OPF, "--\n-- Roles\n--\n\n");
...@@ -746,9 +752,10 @@ dumpRoles(PGconn *conn) ...@@ -746,9 +752,10 @@ dumpRoles(PGconn *conn)
* won't hurt for the CREATE to fail). This is particularly important * won't hurt for the CREATE to fail). This is particularly important
* for the role we are connected as, since even with --clean we will * for the role we are connected as, since even with --clean we will
* have failed to drop it. binary_upgrade cannot generate any errors, * have failed to drop it. binary_upgrade cannot generate any errors,
* so we assume the role is already created. * so we assume the current role is already created.
*/ */
if (!binary_upgrade) if (!binary_upgrade ||
strcmp(PQgetvalue(res, i, i_is_current_user), "f") == 0)
appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename)); appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename));
appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename)); appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment