pg_upgrade 期间的 postgres 超级用户问题

postgres superuser issues during pg_upgrade

我在 Mac OSX 上使用自制程序来管理 postgres 数据库。我正在尝试使用 pg_upgrade 将我的 postgres 安装从 11.9 升级到 13.0。当我 运行 pg_upgrade 我收到以下关于不是超级用户的错误。如果我尝试 运行ning 作为“postgres”用户,我收到一个错误,指出“postgres”用户不是安装用户。

pg_upgrade --old-datadir /usr/local/var/postgresql@11 --new-datadir /usr/local/var/postgres --old-bindir /usr/local/Cellar/postgresql@11/11.9/bin --new-bindir /usr/local/Cellar/postgresql/13.0/bin -c -U Brian
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok

connection to database failed: FATAL:  must be superuser to connect in binary upgrade mode

could not connect to source postmaster started with the command:
"/usr/local/Cellar/postgresql@11/11.9/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/usr/local/var/postgresql@11" -o "-p 50432 -b  -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/usr/local/Cellar'" start
Failure, exiting

以“postgres”用户身份尝试

pg_upgrade --old-datadir /usr/local/var/postgresql@11 --new-datadir /usr/local/var/postgres --old-bindir /usr/local/Cellar/postgresql@11/11.9/bin --new-bindir /usr/local/Cellar/postgresql/13.0/bin -c -U postgres
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user
database user "postgres" is not the install user

我的系统用户名是“Brian”,最初的11.9 数据库是作为该用户安装的,但不知何故它没有超级用户权限。我不确定这是怎么发生的,但直到现在才完全意识到。我的 13.0 数据库似乎已正确设置为“Brian”作为超级用户。

template1=# \du+
                                 List of roles
   Role name   |             Attributes              | Member of  | Description
---------------+-------------------------------------+------------+-------------
 Brian         | Create role, Create DB, Replication | {}         |

当我使用 psql -d template1 -U postgres 登录并尝试更改角色时,出现以下错误。

template1=# alter role Brian with superuser;
ERROR:  role "brian" does not exist
Time: 0.415 ms

如果我以 sudo -u postgres -i 身份登录并尝试更改或创建用户,我也会收到以下错误:

psql -c "alter role Brian with superuser;"
ERROR:  role "brian" does not exist

createuser -s Brian
createuser: error: creation of new role failed: ERROR:  role "Brian" already exists

有谁知道为什么 postgres 对“Brian”和“brian”感到困惑,以及我如何赋予超级用户权限角色“Brian”以便我可以正确执行 pg_upgrade?当我尝试 brew postgresql-upgrade-database 时,它最初给了我同样的超级用户错误,现在,在重新 运行 时,它说一切都已经升级了。

忽略 SQL 中 SQL 标识符的大小写,除非在双引号中:

alter role "Brian" with superuser;

但在命令行中指定时(例如使用-U)大小写不会被忽略。