1

我在 Mac OSX 上使用自制软件来管理 postgres 数据库。我正在尝试使用 pg_upgrade 将我的 postgres 安装从 11.9 升级到 13.0。当我运行 pg_upgrade 时,我收到以下关于不是超级用户的错误。如果我尝试以“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时,它最初给了我相同的超级用户错误,现在,重新运行时,它说一切都已经升级了。

4

1 回答 1

1

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

alter role "Brian" with superuser;

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

于 2020-11-14T00:09:26.783 回答