@@ -121,17 +121,36 @@ check_new_cluster(void)
121121{
122122set_locale_and_encoding (& new_cluster );
123123
124+ check_locale_and_encoding (& old_cluster .controldata ,& new_cluster .controldata );
125+
124126get_db_and_rel_infos (& new_cluster );
125127
126128check_new_cluster_is_empty ();
127- check_for_prepared_transactions (& new_cluster );
128129
129130check_loadable_libraries ();
130131
131- check_locale_and_encoding (& old_cluster .controldata ,& new_cluster .controldata );
132-
133132if (user_opts .transfer_mode == TRANSFER_MODE_LINK )
134133check_hard_link ();
134+
135+ check_is_super_user (& new_cluster );
136+
137+ /*
138+ *We don't restore our own user, so both clusters must match have
139+ *matching install-user oids.
140+ */
141+ if (old_cluster .install_role_oid != new_cluster .install_role_oid )
142+ pg_log (PG_FATAL ,
143+ "Old and new cluster install users have different values for pg_authid.oid.\n" );
144+
145+ /*
146+ *We only allow the install user in the new cluster because other
147+ *defined users might match users defined in the old cluster and
148+ *generate an error during pg_dump restore.
149+ */
150+ if (new_cluster .role_count != 1 )
151+ pg_log (PG_FATAL ,"Only the install user can be defined in the new cluster.\n" );
152+
153+ check_for_prepared_transactions (& new_cluster );
135154}
136155
137156
@@ -580,7 +599,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
580599/*
581600 *check_is_super_user()
582601 *
583- *Make sure we arethe super- user.
602+ *Check we aresuperuser, and out user id and user count
584603 */
585604static void
586605check_is_super_user (ClusterInfo * cluster )
@@ -592,14 +611,27 @@ check_is_super_user(ClusterInfo *cluster)
592611
593612/* Can't use pg_authid because only superusers can view it. */
594613res = executeQueryOrDie (conn ,
595- "SELECT rolsuper "
614+ "SELECT rolsuper, oid "
596615"FROM pg_catalog.pg_roles "
597616"WHERE rolname = current_user" );
598617
599618if (PQntuples (res )!= 1 || strcmp (PQgetvalue (res ,0 ,0 ),"t" )!= 0 )
600619pg_log (PG_FATAL ,"database user \"%s\" is not a superuser\n" ,
601620os_info .user );
602621
622+ cluster -> install_role_oid = atooid (PQgetvalue (res ,0 ,1 ));
623+
624+ PQclear (res );
625+
626+ res = executeQueryOrDie (conn ,
627+ "SELECT COUNT(*) "
628+ "FROM pg_catalog.pg_roles " );
629+
630+ if (PQntuples (res )!= 1 )
631+ pg_log (PG_FATAL ,"could not determine the number of users\n" );
632+
633+ cluster -> role_count = atoi (PQgetvalue (res ,0 ,0 ));
634+
603635PQclear (res );
604636
605637PQfinish (conn );