I recently applied the attached patch to prevent recreation of the
current database user in the dump file when in binary upgrade mode. 
This was necessary because pg_upgrade will fail on any error from a
pg_dumpall restore.

It would be nice of we could do the same for non-binary-upgrade
pg_dumpall dumps, but I assume we can't because the restore might be
performed by a super user who is different from the dump user, right?

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
commit db00d837c17cebf3769fd3b6655812e2d3776f5d
Author: Bruce Momjian <br...@momjian.us>
Date:   Mon Dec 3 19:43:02 2012 -0500

    In pg_upgrade, fix bug where no users were dumped in pg_dumpall
    binary-upgrade mode;  instead only skip dumping the current user.
    
    This bug was introduced in during the removal of split_old_dump().  Bug
    discovered during local testing.

diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
new file mode 100644
index aa4fcbb..088106f
*** a/src/bin/pg_dump/pg_dumpall.c
--- b/src/bin/pg_dump/pg_dumpall.c
*************** dumpRoles(PGconn *conn)
*** 642,648 ****
  				i_rolpassword,
  				i_rolvaliduntil,
  				i_rolreplication,
! 				i_rolcomment;
  	int			i;
  
  	/* note: rolconfig is dumped later */
--- 642,649 ----
  				i_rolpassword,
  				i_rolvaliduntil,
  				i_rolreplication,
! 				i_rolcomment,
! 				i_is_current_user;
  	int			i;
  
  	/* note: rolconfig is dumped later */
*************** dumpRoles(PGconn *conn)
*** 652,658 ****
  						  "rolcreaterole, rolcreatedb, "
  						  "rolcanlogin, rolconnlimit, rolpassword, "
  						  "rolvaliduntil, rolreplication, "
! 			  "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
  						  "FROM pg_authid "
  						  "ORDER BY 2");
  	else if (server_version >= 80200)
--- 653,660 ----
  						  "rolcreaterole, rolcreatedb, "
  						  "rolcanlogin, rolconnlimit, rolpassword, "
  						  "rolvaliduntil, rolreplication, "
! 			  "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)
*************** dumpRoles(PGconn *conn)
*** 661,667 ****
  						  "rolcreaterole, rolcreatedb, "
  						  "rolcanlogin, rolconnlimit, rolpassword, "
  						  "rolvaliduntil, false as rolreplication, "
! 			  "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
  						  "FROM pg_authid "
  						  "ORDER BY 2");
  	else if (server_version >= 80100)
--- 663,670 ----
  						  "rolcreaterole, rolcreatedb, "
  						  "rolcanlogin, rolconnlimit, rolpassword, "
  						  "rolvaliduntil, false as rolreplication, "
! 			  "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)
*************** dumpRoles(PGconn *conn)
*** 670,676 ****
  						  "rolcreaterole, rolcreatedb, "
  						  "rolcanlogin, rolconnlimit, rolpassword, "
  						  "rolvaliduntil, false as rolreplication, "
! 						  "null as rolcomment "
  						  "FROM pg_authid "
  						  "ORDER BY 2");
  	else
--- 673,680 ----
  						  "rolcreaterole, rolcreatedb, "
  						  "rolcanlogin, rolconnlimit, rolpassword, "
  						  "rolvaliduntil, false as rolreplication, "
! 						  "null as rolcomment, "
! 			  			  "rolname = current_user AS is_current_user "
  						  "FROM pg_authid "
  						  "ORDER BY 2");
  	else
*************** dumpRoles(PGconn *conn)
*** 685,691 ****
  						  "passwd as rolpassword, "
  						  "valuntil as rolvaliduntil, "
  						  "false as rolreplication, "
! 						  "null as rolcomment "
  						  "FROM pg_shadow "
  						  "UNION ALL "
  						  "SELECT 0, groname as rolname, "
--- 689,696 ----
  						  "passwd as rolpassword, "
  						  "valuntil as rolvaliduntil, "
  						  "false as rolreplication, "
! 						  "null as rolcomment, "
! 			  			  "rolname = current_user AS is_current_user "
  						  "FROM pg_shadow "
  						  "UNION ALL "
  						  "SELECT 0, groname as rolname, "
*************** dumpRoles(PGconn *conn)
*** 698,704 ****
  						  "null::text as rolpassword, "
  						  "null::abstime as rolvaliduntil, "
  						  "false as rolreplication, "
! 						  "null as rolcomment "
  						  "FROM pg_group "
  						  "WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
  						  " WHERE usename = groname) "
--- 703,709 ----
  						  "null::text as rolpassword, "
  						  "null::abstime as rolvaliduntil, "
  						  "false as rolreplication, "
! 						  "null as rolcomment, false "
  						  "FROM pg_group "
  						  "WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
  						  " WHERE usename = groname) "
*************** dumpRoles(PGconn *conn)
*** 718,723 ****
--- 723,729 ----
  	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");
*************** dumpRoles(PGconn *conn)
*** 746,754 ****
  		 * 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.
  		 */
! 		if (!binary_upgrade)
  			appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename));
  		appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
  
--- 752,761 ----
  		 * 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 current role is already created.
  		 */
! 		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));
  
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to