@@ -642,7 +642,8 @@ dumpRoles(PGconn *conn)
642
642
i_rolpassword ,
643
643
i_rolvaliduntil ,
644
644
i_rolreplication ,
645
- i_rolcomment ;
645
+ i_rolcomment ,
646
+ i_is_current_user ;
646
647
int i ;
647
648
648
649
/* note: rolconfig is dumped later */
@@ -652,7 +653,8 @@ dumpRoles(PGconn *conn)
652
653
"rolcreaterole, rolcreatedb, "
653
654
"rolcanlogin, rolconnlimit, rolpassword, "
654
655
"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 "
656
658
"FROM pg_authid "
657
659
"ORDER BY 2" );
658
660
else if (server_version >= 80200 )
@@ -661,7 +663,8 @@ dumpRoles(PGconn *conn)
661
663
"rolcreaterole, rolcreatedb, "
662
664
"rolcanlogin, rolconnlimit, rolpassword, "
663
665
"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 "
665
668
"FROM pg_authid "
666
669
"ORDER BY 2" );
667
670
else if (server_version >= 80100 )
@@ -670,7 +673,8 @@ dumpRoles(PGconn *conn)
670
673
"rolcreaterole, rolcreatedb, "
671
674
"rolcanlogin, rolconnlimit, rolpassword, "
672
675
"rolvaliduntil, false as rolreplication, "
673
- "null as rolcomment "
676
+ "null as rolcomment, "
677
+ "rolname = current_user AS is_current_user "
674
678
"FROM pg_authid "
675
679
"ORDER BY 2" );
676
680
else
@@ -685,7 +689,8 @@ dumpRoles(PGconn *conn)
685
689
"passwd as rolpassword, "
686
690
"valuntil as rolvaliduntil, "
687
691
"false as rolreplication, "
688
- "null as rolcomment "
692
+ "null as rolcomment, "
693
+ "rolname = current_user AS is_current_user "
689
694
"FROM pg_shadow "
690
695
"UNION ALL "
691
696
"SELECT 0, groname as rolname, "
@@ -698,7 +703,7 @@ dumpRoles(PGconn *conn)
698
703
"null::text as rolpassword, "
699
704
"null::abstime as rolvaliduntil, "
700
705
"false as rolreplication, "
701
- "null as rolcomment "
706
+ "null as rolcomment, false "
702
707
"FROM pg_group "
703
708
"WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
704
709
" WHERE usename = groname) "
@@ -718,6 +723,7 @@ dumpRoles(PGconn *conn)
718
723
i_rolvaliduntil = PQfnumber (res , "rolvaliduntil" );
719
724
i_rolreplication = PQfnumber (res , "rolreplication" );
720
725
i_rolcomment = PQfnumber (res , "rolcomment" );
726
+ i_is_current_user = PQfnumber (res , "is_current_user" );
721
727
722
728
if (PQntuples (res ) > 0 )
723
729
fprintf (OPF , "--\n-- Roles\n--\n\n" );
@@ -746,9 +752,10 @@ dumpRoles(PGconn *conn)
746
752
* won't hurt for the CREATE to fail). This is particularly important
747
753
* for the role we are connected as, since even with --clean we will
748
754
* 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.
750
756
*/
751
- if (!binary_upgrade )
757
+ if (!binary_upgrade ||
758
+ strcmp (PQgetvalue (res , i , i_is_current_user ), "f" ) == 0 )
752
759
appendPQExpBuffer (buf , "CREATE ROLE %s;\n" , fmtId (rolename ));
753
760
appendPQExpBuffer (buf , "ALTER ROLE %s WITH" , fmtId (rolename ));
754
761
0 commit comments