postgresql 数据库用户“postgres”不是安装用户

x7yiwoj4  于 2023-01-12  发布在  PostgreSQL
关注(0)|答案(4)|浏览(238)

我尝试将postgres从9.5升级到9.6。brew upgrade postgresql成功,但运行时

pg_upgrade -b /usr/local/Cellar/postgresql/9.5.3/bin/ -B /usr/local/Cellar/postgresql/9.6.1/bin/ -d /usr/local/var/postgres -D /usr/local/var/postgres9.6 -U postgres

我收到错误

Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user
database user "postgres" is not the install user
Failure, exiting

当尝试在最后不使用-U postgres时,它会变得更奇怪

Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* system OID user data types                ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for roles starting with 'pg_'                      ok
Creating dump of global objects                             ok
Creating dump of database schemas
                                                            ok
Checking for presence of required libraries                 ok
Checking database user is the install user
database user "dimid" is not the install user

那为什么

Checking database user is the install user                  ok
jogvjijk

jogvjijk1#

旧的PostgreSQL集群显然是使用

initdb -U dimid

但新群集是使用不同的超级用户安装的。
您必须使用与旧群集相同的超级用户名创建新群集。

u4vypkhs

u4vypkhs2#

特别是对于homebrew postgresql安装,initdb的默认用户是$USER --因此,如果您只是按照最初的说明进行操作,并执行如下操作

initdb /usr/local/var/postgres -E utf8

安装用户是你的Unix用户名,在我的例子中是'rob',所以在pg_upgrade中添加'-U rob'也可以:

pg_upgrade -b /usr/local/Cellar/postgresql/9.5.4_1/bin -B /usr/local/Cellar/postgresql/9.6.2/bin -d /usr/local/var/postgres95 -D /usr/local/var/postgres -U rob
s3fp2yjn

s3fp2yjn3#

我得到这个是因为 * 目标 * 数据库包含一个额外的用户。
这是我以前安装和升级init脚本的一部分。我从升级initdb中删除了它,升级成功完成。

bvpmtnay

bvpmtnay4#

对于macOS Postgres应用程序的用户:
升级脚本检查$USER在旧数据库中是否有oid 10,如果没有,则会显示相应的错误消息。有关如何解决此问题,请参阅https://support.hashicorp.com/hc/en-us/articles/1500005343202-PostgreSQL-12-Upgrade-Error-database-user-hashicorp-is-not-the-install-user
在我的例子中:

psql postgres -U postgres
SELECT rolname, oid FROM pg_roles;
# check which role has oid 10, in my case role `postgres`
# – as we are postgres right now we have to create an temp user, continue with that:
CREATE ROLE "temp" WITH SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS LOGIN PASSWORD 'temp';

exit # or Ctrl + D

psql postgres -U temp
ALTER ROLE $USER RENAME TO "$USER_";
ALTER ROLE postgres RENAME TO $USER;
CREATE ROLE "postgres" WITH SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS;

根据您自己的数据库,您必须调整这些查询,如链接文章中所述。
P.S.:请注意,使用仍然安装的postgis扩展升级旧数据库并不值得这么麻烦,您必须要么卸载扩展,要么可以使用https://postgresapp.com/documentation/migrating-data.html中描述的另一种升级路径。

相关问题