9
9
10
10
#include "postgres_fe.h"
11
11
12
+ #include "catalog/pg_authid.h"
12
13
#include "mb/pg_wchar.h"
13
14
#include "pg_upgrade.h"
14
15
@@ -19,7 +20,7 @@ static void check_locale_and_encoding(ControlData *oldctrl,
19
20
ControlData * newctrl );
20
21
static bool equivalent_locale (const char * loca , const char * locb );
21
22
static 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 );
23
24
static void check_for_prepared_transactions (ClusterInfo * cluster );
24
25
static void check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster );
25
26
static 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)
94
95
/*
95
96
* Check for various failure cases
96
97
*/
97
- check_is_super_user (& old_cluster );
98
+ check_is_install_user (& old_cluster );
98
99
check_for_prepared_transactions (& old_cluster );
99
100
check_for_reg_data_type_usage (& old_cluster );
100
101
check_for_isn_and_int8_passing_mismatch (& old_cluster );
@@ -158,22 +159,7 @@ check_new_cluster(void)
158
159
if (user_opts .transfer_mode == TRANSFER_MODE_LINK )
159
160
check_hard_link ();
160
161
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 );
177
163
178
164
check_for_prepared_transactions (& new_cluster );
179
165
}
@@ -698,30 +684,35 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
698
684
699
685
700
686
/*
701
- * check_is_super_user ()
687
+ * check_is_install_user ()
702
688
*
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.
704
691
*/
705
692
static void
706
- check_is_super_user (ClusterInfo * cluster )
693
+ check_is_install_user (ClusterInfo * cluster )
707
694
{
708
695
PGresult * res ;
709
696
PGconn * conn = connectToServer (cluster , "template1" );
710
697
711
- prep_status ("Checking database user is a superuser " );
698
+ prep_status ("Checking database user is the install user " );
712
699
713
700
/* Can't use pg_authid because only superusers can view it. */
714
701
res = executeQueryOrDie (conn ,
715
702
"SELECT rolsuper, oid "
716
703
"FROM pg_catalog.pg_roles "
717
704
"WHERE rolname = current_user" );
718
705
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" ,
721
714
os_info .user );
722
715
723
- cluster -> install_role_oid = atooid (PQgetvalue (res , 0 , 1 ));
724
-
725
716
PQclear (res );
726
717
727
718
res = executeQueryOrDie (conn ,
@@ -731,7 +722,13 @@ check_is_super_user(ClusterInfo *cluster)
731
722
if (PQntuples (res ) != 1 )
732
723
pg_fatal ("could not determine the number of users\n" );
733
724
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" );
735
732
736
733
PQclear (res );
737
734
0 commit comments