@@ -118,18 +118,38 @@ check_new_cluster(void)
118
118
{
119
119
set_locale_and_encoding (& new_cluster );
120
120
121
+ check_locale_and_encoding (& old_cluster .controldata ,& new_cluster .controldata );
122
+
121
123
get_db_and_rel_infos (& new_cluster );
122
124
123
125
check_new_cluster_is_empty ();
124
- check_for_prepared_transactions ( & new_cluster );
126
+
125
127
check_old_cluster_has_new_cluster_dbs ();
126
128
127
129
check_loadable_libraries ();
128
130
129
- check_locale_and_encoding (& old_cluster .controldata ,& new_cluster .controldata );
130
-
131
131
if (user_opts .transfer_mode == TRANSFER_MODE_LINK )
132
132
check_hard_link ();
133
+
134
+ check_is_super_user (& new_cluster );
135
+
136
+ /*
137
+ *We don't restore our own user, so both clusters must match have
138
+ *matching install-user oids.
139
+ */
140
+ if (old_cluster .install_role_oid != new_cluster .install_role_oid )
141
+ pg_log (PG_FATAL ,
142
+ "Old and new cluster install users have different values for pg_authid.oid.\n" );
143
+
144
+ /*
145
+ *We only allow the install user in the new cluster because other
146
+ *defined users might match users defined in the old cluster and
147
+ *generate an error during pg_dump restore.
148
+ */
149
+ if (new_cluster .role_count != 1 )
150
+ pg_log (PG_FATAL ,"Only the install user can be defined in the new cluster.\n" );
151
+
152
+ check_for_prepared_transactions (& new_cluster );
133
153
}
134
154
135
155
@@ -485,7 +505,7 @@ create_script_for_old_cluster_deletion(
485
505
/*
486
506
*check_is_super_user()
487
507
*
488
- *Make sure we arethe super- user.
508
+ *Check we aresuperuser, and out user id and user count
489
509
*/
490
510
static void
491
511
check_is_super_user (ClusterInfo * cluster )
@@ -497,14 +517,27 @@ check_is_super_user(ClusterInfo *cluster)
497
517
498
518
/* Can't use pg_authid because only superusers can view it. */
499
519
res = executeQueryOrDie (conn ,
500
- "SELECT rolsuper "
520
+ "SELECT rolsuper, oid "
501
521
"FROM pg_catalog.pg_roles "
502
522
"WHERE rolname = current_user" );
503
523
504
524
if (PQntuples (res )!= 1 || strcmp (PQgetvalue (res ,0 ,0 ),"t" )!= 0 )
505
525
pg_log (PG_FATAL ,"database user \"%s\" is not a superuser\n" ,
506
526
os_info .user );
507
527
528
+ cluster -> install_role_oid = atooid (PQgetvalue (res ,0 ,1 ));
529
+
530
+ PQclear (res );
531
+
532
+ res = executeQueryOrDie (conn ,
533
+ "SELECT COUNT(*) "
534
+ "FROM pg_catalog.pg_roles " );
535
+
536
+ if (PQntuples (res )!= 1 )
537
+ pg_log (PG_FATAL ,"could not determine the number of users\n" );
538
+
539
+ cluster -> role_count = atoi (PQgetvalue (res ,0 ,0 ));
540
+
508
541
PQclear (res );
509
542
510
543
PQfinish (conn );