@ -642,7 +642,8 @@ dumpRoles(PGconn *conn)
i_rolpassword ,
i_rolvaliduntil ,
i_rolreplication ,
i_rolcomment ;
i_rolcomment ,
i_is_current_user ;
int i ;
/* note: rolconfig is dumped later */
@ -652,7 +653,8 @@ dumpRoles(PGconn *conn)
" rolcreaterole, rolcreatedb, "
" rolcanlogin, rolconnlimit, rolpassword, "
" rolvaliduntil, rolreplication, "
" pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
" pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
" rolname = current_user AS is_current_user "
" FROM pg_authid "
" ORDER BY 2 " ) ;
else if ( server_version > = 80200 )
@ -661,7 +663,8 @@ dumpRoles(PGconn *conn)
" rolcreaterole, rolcreatedb, "
" rolcanlogin, rolconnlimit, rolpassword, "
" rolvaliduntil, false as rolreplication, "
" pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
" pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
" rolname = current_user AS is_current_user "
" FROM pg_authid "
" ORDER BY 2 " ) ;
else if ( server_version > = 80100 )
@ -670,7 +673,8 @@ dumpRoles(PGconn *conn)
" rolcreaterole, rolcreatedb, "
" rolcanlogin, rolconnlimit, rolpassword, "
" rolvaliduntil, false as rolreplication, "
" null as rolcomment "
" null as rolcomment, "
" rolname = current_user AS is_current_user "
" FROM pg_authid "
" ORDER BY 2 " ) ;
else
@ -685,7 +689,8 @@ dumpRoles(PGconn *conn)
" passwd as rolpassword, "
" valuntil as rolvaliduntil, "
" false as rolreplication, "
" null as rolcomment "
" null as rolcomment, "
" rolname = current_user AS is_current_user "
" FROM pg_shadow "
" UNION ALL "
" SELECT 0, groname as rolname, "
@ -698,7 +703,7 @@ dumpRoles(PGconn *conn)
" null::text as rolpassword, "
" null::abstime as rolvaliduntil, "
" false as rolreplication, "
" null as rolcomment "
" null as rolcomment, false "
" FROM pg_group "
" WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
" WHERE usename = groname) "
@ -718,6 +723,7 @@ dumpRoles(PGconn *conn)
i_rolvaliduntil = PQfnumber ( res , " rolvaliduntil " ) ;
i_rolreplication = PQfnumber ( res , " rolreplication " ) ;
i_rolcomment = PQfnumber ( res , " rolcomment " ) ;
i_is_current_user = PQfnumber ( res , " is_current_user " ) ;
if ( PQntuples ( res ) > 0 )
fprintf ( OPF , " -- \n -- Roles \n -- \n \n " ) ;
@ -746,9 +752,10 @@ dumpRoles(PGconn *conn)
* won ' t hurt for the CREATE to fail ) . This is particularly important
* for the role we are connected as , since even with - - clean we will
* have failed to drop it . binary_upgrade cannot generate any errors ,
* so we assume the role is already created .
* so we assume the current role is already created .
*/
if ( ! binary_upgrade )
if ( ! binary_upgrade | |
strcmp ( PQgetvalue ( res , i , i_is_current_user ) , " f " ) = = 0 )
appendPQExpBuffer ( buf , " CREATE ROLE %s; \n " , fmtId ( rolename ) ) ;
appendPQExpBuffer ( buf , " ALTER ROLE %s WITH " , fmtId ( rolename ) ) ;