@@ -650,7 +650,8 @@ dumpRoles(PGconn *conn)
650
650
{
651
651
PQExpBuffer buf = createPQExpBuffer ();
652
652
PGresult * res ;
653
- int i_rolname ,
653
+ int i_oid ,
654
+ i_rolname ,
654
655
i_rolsuper ,
655
656
i_rolinherit ,
656
657
i_rolcreaterole ,
@@ -667,34 +668,34 @@ dumpRoles(PGconn *conn)
667
668
/* note: rolconfig is dumped later */
668
669
if (server_version >= 90100 )
669
670
printfPQExpBuffer (buf ,
670
- "SELECT rolname, rolsuper, rolinherit, "
671
+ "SELECT oid, rolname, rolsuper, rolinherit, "
671
672
"rolcreaterole, rolcreatedb, rolcatupdate, "
672
673
"rolcanlogin, rolconnlimit, rolpassword, "
673
674
"rolvaliduntil, rolreplication, "
674
675
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
675
676
"FROM pg_authid "
676
- "ORDER BY 1 " );
677
+ "ORDER BY 2 " );
677
678
else if (server_version >= 80200 )
678
679
printfPQExpBuffer (buf ,
679
- "SELECT rolname, rolsuper, rolinherit, "
680
+ "SELECT oid, rolname, rolsuper, rolinherit, "
680
681
"rolcreaterole, rolcreatedb, rolcatupdate, "
681
682
"rolcanlogin, rolconnlimit, rolpassword, "
682
683
"rolvaliduntil, false as rolreplication, "
683
684
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
684
685
"FROM pg_authid "
685
- "ORDER BY 1 " );
686
+ "ORDER BY 2 " );
686
687
else if (server_version >= 80100 )
687
688
printfPQExpBuffer (buf ,
688
- "SELECT rolname, rolsuper, rolinherit, "
689
+ "SELECT oid, rolname, rolsuper, rolinherit, "
689
690
"rolcreaterole, rolcreatedb, rolcatupdate, "
690
691
"rolcanlogin, rolconnlimit, rolpassword, "
691
692
"rolvaliduntil, false as rolreplication, "
692
693
"null as rolcomment "
693
694
"FROM pg_authid "
694
- "ORDER BY 1 " );
695
+ "ORDER BY 2 " );
695
696
else
696
697
printfPQExpBuffer (buf ,
697
- "SELECT usename as rolname, "
698
+ "SELECT 0, usename as rolname, "
698
699
"usesuper as rolsuper, "
699
700
"true as rolinherit, "
700
701
"usesuper as rolcreaterole, "
@@ -708,7 +709,7 @@ dumpRoles(PGconn *conn)
708
709
"null as rolcomment "
709
710
"FROM pg_shadow "
710
711
"UNION ALL "
711
- "SELECT groname as rolname, "
712
+ "SELECT 0, groname as rolname, "
712
713
"false as rolsuper, "
713
714
"true as rolinherit, "
714
715
"false as rolcreaterole, "
@@ -723,10 +724,11 @@ dumpRoles(PGconn *conn)
723
724
"FROM pg_group "
724
725
"WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
725
726
" WHERE usename = groname) "
726
- "ORDER BY 1 " );
727
+ "ORDER BY 2 " );
727
728
728
729
res = executeQuery (conn , buf -> data );
729
730
731
+ i_oid = PQfnumber (res , "oid" );
730
732
i_rolname = PQfnumber (res , "rolname" );
731
733
i_rolsuper = PQfnumber (res , "rolsuper" );
732
734
i_rolinherit = PQfnumber (res , "rolinherit" );
@@ -751,6 +753,16 @@ dumpRoles(PGconn *conn)
751
753
752
754
resetPQExpBuffer (buf );
753
755
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
+
754
766
/*
755
767
* We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
756
768
* will acquire the right properties even if it already exists (ie, it
0 commit comments