簡體   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