@@ -650,7 +650,8 @@ dumpRoles(PGconn *conn)
650650{
651651PQExpBuffer buf = createPQExpBuffer ();
652652PGresult * res ;
653- int i_rolname ,
653+ int i_oid ,
654+ i_rolname ,
654655i_rolsuper ,
655656i_rolinherit ,
656657i_rolcreaterole ,
@@ -667,34 +668,34 @@ dumpRoles(PGconn *conn)
667668/* note: rolconfig is dumped later */
668669if (server_version >=90100 )
669670printfPQExpBuffer (buf ,
670- "SELECT rolname, rolsuper, rolinherit, "
671+ "SELECToid, 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 BY1 " );
677+ "ORDER BY2 " );
677678else if (server_version >=80200 )
678679printfPQExpBuffer (buf ,
679- "SELECT rolname, rolsuper, rolinherit, "
680+ "SELECToid, 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 BY1 " );
686+ "ORDER BY2 " );
686687else if (server_version >=80100 )
687688printfPQExpBuffer (buf ,
688- "SELECT rolname, rolsuper, rolinherit, "
689+ "SELECToid, 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 BY1 " );
695+ "ORDER BY2 " );
695696else
696697printfPQExpBuffer (buf ,
697- "SELECT usename as rolname, "
698+ "SELECT0, 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+ "SELECT0, 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 BY1 " );
727+ "ORDER BY2 " );
727728
728729res = executeQuery (conn ,buf -> data );
729730
731+ i_oid = PQfnumber (res ,"oid" );
730732i_rolname = PQfnumber (res ,"rolname" );
731733i_rolsuper = PQfnumber (res ,"rolsuper" );
732734i_rolinherit = PQfnumber (res ,"rolinherit" );
@@ -751,6 +753,16 @@ dumpRoles(PGconn *conn)
751753
752754resetPQExpBuffer (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