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

Commitee646df

Browse files
committed
pg_upgrade: assume user is install user
The user specified to the upgrade was effectively the install user, butthat was not clearly stated in the comments, documentation, or errormessages.
1 parentb4bd6f6 commitee646df

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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);
2021
staticboolequivalent_locale(constchar*loca,constchar*locb);
2122
staticboolequivalent_encoding(constchar*chara,constchar*charb);
22-
staticvoidcheck_is_super_user(ClusterInfo*cluster);
23+
staticvoidcheck_is_install_user(ClusterInfo*cluster);
2324
staticvoidcheck_for_prepared_transactions(ClusterInfo*cluster);
2425
staticvoidcheck_for_isn_and_int8_passing_mismatch(ClusterInfo*cluster);
2526
staticvoidcheck_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
*/
705692
staticvoid
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 isa superuser");
698+
prep_status("Checking database user isthe 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

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ typedef struct
256256
charmajor_version_str[64];/* string PG_VERSION of cluster */
257257
uint32bin_version;/* version returned from pg_ctl */
258258
Oidpg_database_oid;/* OID of pg_database relation */
259-
Oidinstall_role_oid;/* OID of connected role */
260-
Oidrole_count;/* number of roles defined in the cluster */
261259
constchar*tablespace_suffix;/* directory specification */
262260
}ClusterInfo;
263261

‎doc/src/sgml/pgupgrade.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
<varlistentry>
165165
<term><option>-U</option> <replaceable>username</></term>
166166
<term><option>--username=</option><replaceable>username</></term>
167-
<listitem><para>cluster'ssuper user name; environment
167+
<listitem><para>cluster'sinstall user name; environment
168168
variable <envar>PGUSER</></para></listitem>
169169
</varlistentry>
170170

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp