繁体   English   中英

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

[英]database user "postgres" is not the install user

我正在尝试将 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

旧的 PostgreSQL 集群显然是用

initdb -U dimid

但是新集群是由不同的超级用户安装的。

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

特别是对于自制的 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

我得到这个是因为目标数据库包含一个额外的用户。

这以前是我的安装和升级初始化脚本的一部分。 我从升级 initdb 中删除了它,升级成功完成。

对于 macOS Postgres App 的用户:

升级脚本检查 $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;

根据您自己的数据库,您必须按照链接文章中的描述调整这些查询。

PS:请注意,使用仍然安装的 postgis 扩展升级旧数据库并不值得这么麻烦,您必须卸载扩展或可以按照https://postgresapp.com/documentation/migrating-data 中所述的其他升级路径。 html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM