@@ -642,7 +642,8 @@ dumpRoles(PGconn *conn)
642642i_rolpassword ,
643643i_rolvaliduntil ,
644644i_rolreplication ,
645- i_rolcomment ;
645+ i_rolcomment ,
646+ i_is_current_user ;
646647int 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" );
658660else 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" );
667670else 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" );
676680else
@@ -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)
718723i_rolvaliduntil = PQfnumber (res ,"rolvaliduntil" );
719724i_rolreplication = PQfnumber (res ,"rolreplication" );
720725i_rolcomment = PQfnumber (res ,"rolcomment" );
726+ i_is_current_user = PQfnumber (res ,"is_current_user" );
721727
722728if (PQntuples (res )> 0 )
723729fprintf (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 thecurrent role is already created.
750756 */
751- if (!binary_upgrade )
757+ if (!binary_upgrade ||
758+ strcmp (PQgetvalue (res ,i ,i_is_current_user ),"f" )== 0 )
752759appendPQExpBuffer (buf ,"CREATE ROLE %s;\n" ,fmtId (rolename ));
753760appendPQExpBuffer (buf ,"ALTER ROLE %s WITH" ,fmtId (rolename ));
754761