postgresql 以 postgres 身份登录但收到错误 createuser:创建新角色失败:错误:必须是超级用户才能创建超级用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15791406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logged in as postgres but getting the error createuser: creation of new role failed: ERROR: must be superuser to create superusers
提问by Eric Baldwin
I need to create a superuser so I can create a db, but I'm having trouble with this. I'm logged in as the user postgres:
我需要创建一个超级用户,以便我可以创建一个数据库,但是我遇到了这个问题。我以用户 postgres 登录:
sudo su - postgres
But when I try to create a superuser, I get the following problem:
但是当我尝试创建超级用户时,出现以下问题:
$createuser glassboard;
Shall the new role be a superuser? (y/n) y
createuser: creation of new role failed: ERROR: must be superuser to create superusers
createuser:创建新角色失败:错误:必须是超级用户才能创建超级用户
This also happens if I try to create a new user in psql and then make him a superuser:
如果我尝试在 psql 中创建一个新用户然后让他成为超级用户,也会发生这种情况:
$ psql -U postgres
psql (9.1.4)
Type "help" for help.
postgres=> create user glassboard
postgres-> ;
ERROR: permission denied to create role
How do I create a superuser?
如何创建超级用户?
output of \du
in postgres:
\du
在 postgres 中的输出:
postgres=> \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
main | Superuser, Create role, Create DB, Replication | {}
postgres | | {}
回答by Daniel Vérité
Some OSX packages don't create a postgres
superuser database account. The superuser is named differently, in your case it's main
.
某些 OSX 软件包不会创建postgres
超级用户数据库帐户。超级用户的名称不同,在您的情况下是main
.
When you do psql -U main
without specifying a database, it defaults to the same name as the user.
If you don't have a database named main
, indicate a different database with the -d
option.
当您psql -U main
不指定数据库时,它默认为与用户相同的名称。如果您没有名为 的main
数据库,请使用该-d
选项指示不同的数据库。
If you have no database to connect to, use template1
如果您没有要连接的数据库,请使用 template1
psql -U main -d template1
If still you want to grant superuser to postgres
, do once logged inside psql:
如果您仍然想授予超级用户postgres
,请在登录 psql 后执行:
alter user postgres superuser;
回答by yellavon
In my case on PostgreSQL 9.2, the postgres
superuser was created, but when I went to create additional superusers from the postgres
user, I was never prompted with Shall the new role be a superuser? (y/n)
so the new user was created with default permissions. To fix this, I just ran this command as the postgres
user: ALTER USER myuser WITH SUPERUSER;
就我在 PostgreSQL 9.2 上的情况而言,postgres
创建了超级用户,但是当我从该postgres
用户创建其他超级用户时,我从未收到提示,Shall the new role be a superuser? (y/n)
因此使用默认权限创建了新用户。为了解决这个问题,我只是以postgres
用户身份运行了这个命令:ALTER USER myuser WITH SUPERUSER;
回答by leandroico
I am using PostgreSQL 9.6 (not saying my solution shouldn't work for older or newer versions) on macOS Sierra (10.12.2) and what really worked for me was to create another user with the following command line:
我在 macOS Sierra (10.12.2) 上使用 PostgreSQL 9.6(不是说我的解决方案不适用于旧版本或新版本),真正对我有用的是使用以下命令行创建另一个用户:
createuser -s anotheruser
回答by Adrian Stanica
Had the same issue about not being able to create a new user, after creating a database and logging into that database as the superuser.
在创建数据库并以超级用户身份登录该数据库后,遇到了无法创建新用户的相同问题。
This is what worked for me (unfortunately I didn't have time to study the why), on Debian 10, Postgresql12
这对我有用(不幸的是我没有时间研究原因),在 Debian 10 上,Postgresql12
Log into the system default db (postgres) as the default superuser (in my case I had just installed it, so).
以默认超级用户身份登录系统默认数据库(postgres)(在我的情况下,我刚刚安装了它,所以)。
psql -d postgres
psql -d postgres
and then I was able to create the user, with exactly the same command line that didn't work when I was logged under the database I had created: create user xxxx with password 'yyyyyy';
然后我能够创建用户,使用完全相同的命令行,当我在我创建的数据库下登录时不起作用:创建用户 xxxx,密码为“yyyyyy”;
Then I granted all on the new database that I had created
然后我授予了我创建的新数据库的所有权限
grant all on database newly_created_database to xxxx;
将数据库 new_created_database 上的所有内容都授予 xxxx;