Skip to content

Commit db00d83

Browse files
committed
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.
1 parent 7510bec commit db00d83

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/bin/pg_dump/pg_dumpall.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ dumpRoles(PGconn *conn)
642642
i_rolpassword,
643643
i_rolvaliduntil,
644644
i_rolreplication,
645-
i_rolcomment;
645+
i_rolcomment,
646+
i_is_current_user;
646647
int i;
647648

648649
/* note: rolconfig is dumped later */
@@ -652,7 +653,8 @@ dumpRoles(PGconn *conn)
652653
"rolcreaterole, rolcreatedb, "
653654
"rolcanlogin, rolconnlimit, rolpassword, "
654655
"rolvaliduntil, rolreplication, "
655-
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
656+
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
657+
"rolname = current_user AS is_current_user "
656658
"FROM pg_authid "
657659
"ORDER BY 2");
658660
else if (server_version >= 80200)
@@ -661,7 +663,8 @@ dumpRoles(PGconn *conn)
661663
"rolcreaterole, rolcreatedb, "
662664
"rolcanlogin, rolconnlimit, rolpassword, "
663665
"rolvaliduntil, false as rolreplication, "
664-
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
666+
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
667+
"rolname = current_user AS is_current_user "
665668
"FROM pg_authid "
666669
"ORDER BY 2");
667670
else if (server_version >= 80100)
@@ -670,7 +673,8 @@ dumpRoles(PGconn *conn)
670673
"rolcreaterole, rolcreatedb, "
671674
"rolcanlogin, rolconnlimit, rolpassword, "
672675
"rolvaliduntil, false as rolreplication, "
673-
"null as rolcomment "
676+
"null as rolcomment, "
677+
"rolname = current_user AS is_current_user "
674678
"FROM pg_authid "
675679
"ORDER BY 2");
676680
else
@@ -685,7 +689,8 @@ dumpRoles(PGconn *conn)
685689
"passwd as rolpassword, "
686690
"valuntil as rolvaliduntil, "
687691
"false as rolreplication, "
688-
"null as rolcomment "
692+
"null as rolcomment, "
693+
"rolname = current_user AS is_current_user "
689694
"FROM pg_shadow "
690695
"UNION ALL "
691696
"SELECT 0, groname as rolname, "
@@ -698,7 +703,7 @@ dumpRoles(PGconn *conn)
698703
"null::text as rolpassword, "
699704
"null::abstime as rolvaliduntil, "
700705
"false as rolreplication, "
701-
"null as rolcomment "
706+
"null as rolcomment, false "
702707
"FROM pg_group "
703708
"WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
704709
" WHERE usename = groname) "
@@ -718,6 +723,7 @@ dumpRoles(PGconn *conn)
718723
i_rolvaliduntil = PQfnumber(res, "rolvaliduntil");
719724
i_rolreplication = PQfnumber(res, "rolreplication");
720725
i_rolcomment = PQfnumber(res, "rolcomment");
726+
i_is_current_user = PQfnumber(res, "is_current_user");
721727

722728
if (PQntuples(res) > 0)
723729
fprintf(OPF, "--\n-- Roles\n--\n\n");
@@ -746,9 +752,10 @@ dumpRoles(PGconn *conn)
746752
* won't hurt for the CREATE to fail). This is particularly important
747753
* for the role we are connected as, since even with --clean we will
748754
* have failed to drop it. binary_upgrade cannot generate any errors,
749-
* so we assume the role is already created.
755+
* so we assume the current role is already created.
750756
*/
751-
if (!binary_upgrade)
757+
if (!binary_upgrade ||
758+
strcmp(PQgetvalue(res, i, i_is_current_user), "f") == 0)
752759
appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename));
753760
appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
754761

0 commit comments

Comments
 (0)