@@ -650,7 +650,8 @@ dumpRoles(PGconn *conn)
650650{
651651 PQExpBuffer buf = createPQExpBuffer ();
652652 PGresult * res ;
653- int i_rolname ,
653+ int i_oid ,
654+ i_rolname ,
654655 i_rolsuper ,
655656 i_rolinherit ,
656657 i_rolcreaterole ,
@@ -667,34 +668,34 @@ dumpRoles(PGconn *conn)
667668 /* note: rolconfig is dumped later */
668669 if (server_version >= 90100 )
669670 printfPQExpBuffer (buf ,
670- "SELECT rolname, rolsuper, rolinherit, "
671+ "SELECT oid, rolname, rolsuper, rolinherit, "
671672 "rolcreaterole, rolcreatedb, rolcatupdate, "
672673 "rolcanlogin, rolconnlimit, rolpassword, "
673674 "rolvaliduntil, rolreplication, "
674675 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
675676 "FROM pg_authid "
676- "ORDER BY 1 " );
677+ "ORDER BY 2 " );
677678 else if (server_version >= 80200 )
678679 printfPQExpBuffer (buf ,
679- "SELECT rolname, rolsuper, rolinherit, "
680+ "SELECT oid, rolname, rolsuper, rolinherit, "
680681 "rolcreaterole, rolcreatedb, rolcatupdate, "
681682 "rolcanlogin, rolconnlimit, rolpassword, "
682683 "rolvaliduntil, false as rolreplication, "
683684 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
684685 "FROM pg_authid "
685- "ORDER BY 1 " );
686+ "ORDER BY 2 " );
686687 else if (server_version >= 80100 )
687688 printfPQExpBuffer (buf ,
688- "SELECT rolname, rolsuper, rolinherit, "
689+ "SELECT oid, rolname, rolsuper, rolinherit, "
689690 "rolcreaterole, rolcreatedb, rolcatupdate, "
690691 "rolcanlogin, rolconnlimit, rolpassword, "
691692 "rolvaliduntil, false as rolreplication, "
692693 "null as rolcomment "
693694 "FROM pg_authid "
694- "ORDER BY 1 " );
695+ "ORDER BY 2 " );
695696 else
696697 printfPQExpBuffer (buf ,
697- "SELECT usename as rolname, "
698+ "SELECT 0, usename as rolname, "
698699 "usesuper as rolsuper, "
699700 "true as rolinherit, "
700701 "usesuper as rolcreaterole, "
@@ -708,7 +709,7 @@ dumpRoles(PGconn *conn)
708709 "null as rolcomment "
709710 "FROM pg_shadow "
710711 "UNION ALL "
711- "SELECT groname as rolname, "
712+ "SELECT 0, groname as rolname, "
712713 "false as rolsuper, "
713714 "true as rolinherit, "
714715 "false as rolcreaterole, "
@@ -723,10 +724,11 @@ dumpRoles(PGconn *conn)
723724 "FROM pg_group "
724725 "WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
725726 " WHERE usename = groname) "
726- "ORDER BY 1 " );
727+ "ORDER BY 2 " );
727728
728729 res = executeQuery (conn , buf -> data );
729730
731+ i_oid = PQfnumber (res , "oid" );
730732 i_rolname = PQfnumber (res , "rolname" );
731733 i_rolsuper = PQfnumber (res , "rolsuper" );
732734 i_rolinherit = PQfnumber (res , "rolinherit" );
@@ -751,6 +753,16 @@ dumpRoles(PGconn *conn)
751753
752754 resetPQExpBuffer (buf );
753755
756+ if (binary_upgrade )
757+ {
758+ Oid auth_oid = atooid (PQgetvalue (res , i , i_oid ));
759+
760+ appendPQExpBuffer (buf , "\n-- For binary upgrade, must preserve pg_authid.oid\n" );
761+ appendPQExpBuffer (buf ,
762+ "SELECT binary_upgrade.set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n" ,
763+ auth_oid );
764+ }
765+
754766 /*
755767 * We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
756768 * will acquire the right properties even if it already exists (ie, it
0 commit comments