Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9212e3

Browse files
committed
In pg_upgrade, verify that the install user has the same oid on both
clusters, and make sure the new cluster has no additional users.Backpatch to 9.1.
1 parentc0a6f9c commitb9212e3

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,36 @@ check_new_cluster(void)
121121
{
122122
set_locale_and_encoding(&new_cluster);
123123

124+
check_locale_and_encoding(&old_cluster.controldata,&new_cluster.controldata);
125+
124126
get_db_and_rel_infos(&new_cluster);
125127

126128
check_new_cluster_is_empty();
127-
check_for_prepared_transactions(&new_cluster);
128129

129130
check_loadable_libraries();
130131

131-
check_locale_and_encoding(&old_cluster.controldata,&new_cluster.controldata);
132-
133132
if (user_opts.transfer_mode==TRANSFER_MODE_LINK)
134133
check_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 surewe arethe super-user.
602+
*Checkwe aresuperuser, and outuser id and user count
584603
*/
585604
staticvoid
586605
check_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. */
594613
res=executeQueryOrDie(conn,
595-
"SELECT rolsuper "
614+
"SELECT rolsuper, oid "
596615
"FROM pg_catalog.pg_roles "
597616
"WHERE rolname = current_user");
598617

599618
if (PQntuples(res)!=1||strcmp(PQgetvalue(res,0,0),"t")!=0)
600619
pg_log(PG_FATAL,"database user \"%s\" is not a superuser\n",
601620
os_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+
603635
PQclear(res);
604636

605637
PQfinish(conn);

‎contrib/pg_upgrade/pg_upgrade.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*We control all assignments of pg_enum.oid because these oids are stored
3030
*in user tables as enum values.
3131
*
32-
*We control all assignments ofpg_auth.oid because these oids are stored
32+
*We control all assignments ofpg_authid.oid because these oids are stored
3333
*in pg_largeobject_metadata.
3434
*/
3535

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ typedef struct
232232
charmajor_version_str[64];/* string PG_VERSION of cluster */
233233
uint32bin_version;/* version returned from pg_ctl */
234234
Oidpg_database_oid;/* OID of pg_database relation */
235+
Oidinstall_role_oid;/* OID of connected role */
236+
Oidrole_count;/* number of roles defined in the cluster */
235237
char*tablespace_suffix;/* directory specification */
236238
}ClusterInfo;
237239

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp