99
1010#include "postgres_fe.h"
1111
12+ #include "catalog/pg_authid.h"
1213#include "mb/pg_wchar.h"
1314#include "pg_upgrade.h"
1415
@@ -19,7 +20,7 @@ static void check_locale_and_encoding(ControlData *oldctrl,
1920 ControlData * newctrl );
2021static bool equivalent_locale (const char * loca , const char * locb );
2122static bool equivalent_encoding (const char * chara , const char * charb );
22- static void check_is_super_user (ClusterInfo * cluster );
23+ static void check_is_install_user (ClusterInfo * cluster );
2324static void check_for_prepared_transactions (ClusterInfo * cluster );
2425static void check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster );
2526static void check_for_reg_data_type_usage (ClusterInfo * cluster );
@@ -94,7 +95,7 @@ check_and_dump_old_cluster(bool live_check, char **sequence_script_file_name)
9495 /*
9596 * Check for various failure cases
9697 */
97- check_is_super_user (& old_cluster );
98+ check_is_install_user (& old_cluster );
9899 check_for_prepared_transactions (& old_cluster );
99100 check_for_reg_data_type_usage (& old_cluster );
100101 check_for_isn_and_int8_passing_mismatch (& old_cluster );
@@ -158,22 +159,7 @@ check_new_cluster(void)
158159 if (user_opts .transfer_mode == TRANSFER_MODE_LINK )
159160 check_hard_link ();
160161
161- check_is_super_user (& new_cluster );
162-
163- /*
164- * We don't restore our own user, so both clusters must match have
165- * matching install-user oids.
166- */
167- if (old_cluster .install_role_oid != new_cluster .install_role_oid )
168- pg_fatal ("Old and new cluster install users have different values for pg_authid.oid.\n" );
169-
170- /*
171- * We only allow the install user in the new cluster because other defined
172- * users might match users defined in the old cluster and generate an
173- * error during pg_dump restore.
174- */
175- if (new_cluster .role_count != 1 )
176- pg_fatal ("Only the install user can be defined in the new cluster.\n" );
162+ check_is_install_user (& new_cluster );
177163
178164 check_for_prepared_transactions (& new_cluster );
179165}
@@ -698,30 +684,35 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
698684
699685
700686/*
701- * check_is_super_user ()
687+ * check_is_install_user ()
702688 *
703- * Check we are superuser, and output user id and user count
689+ * Check we are the install user, and that the new cluster
690+ * has no other users.
704691 */
705692static void
706- check_is_super_user (ClusterInfo * cluster )
693+ check_is_install_user (ClusterInfo * cluster )
707694{
708695 PGresult * res ;
709696 PGconn * conn = connectToServer (cluster , "template1" );
710697
711- prep_status ("Checking database user is a superuser " );
698+ prep_status ("Checking database user is the install user " );
712699
713700 /* Can't use pg_authid because only superusers can view it. */
714701 res = executeQueryOrDie (conn ,
715702 "SELECT rolsuper, oid "
716703 "FROM pg_catalog.pg_roles "
717704 "WHERE rolname = current_user" );
718705
719- if (PQntuples (res ) != 1 || strcmp (PQgetvalue (res , 0 , 0 ), "t" ) != 0 )
720- pg_fatal ("database user \"%s\" is not a superuser\n" ,
706+ /*
707+ * We only allow the install user in the new cluster (see comment below)
708+ * and we preserve pg_authid.oid, so this must be the install user in
709+ * the old cluster too.
710+ */
711+ if (PQntuples (res ) != 1 ||
712+ atooid (PQgetvalue (res , 0 , 1 )) != BOOTSTRAP_SUPERUSERID )
713+ pg_fatal ("database user \"%s\" is not the install user\n" ,
721714 os_info .user );
722715
723- cluster -> install_role_oid = atooid (PQgetvalue (res , 0 , 1 ));
724-
725716 PQclear (res );
726717
727718 res = executeQueryOrDie (conn ,
@@ -731,7 +722,13 @@ check_is_super_user(ClusterInfo *cluster)
731722 if (PQntuples (res ) != 1 )
732723 pg_fatal ("could not determine the number of users\n" );
733724
734- cluster -> role_count = atoi (PQgetvalue (res , 0 , 0 ));
725+ /*
726+ * We only allow the install user in the new cluster because other defined
727+ * users might match users defined in the old cluster and generate an
728+ * error during pg_dump restore.
729+ */
730+ if (cluster == & new_cluster && atooid (PQgetvalue (res , 0 , 0 )) != 1 )
731+ pg_fatal ("Only the install user can be defined in the new cluster.\n" );
735732
736733 PQclear (res );
737734
0 commit comments