以 postgres 身份登录但收到错误 createuser:创建新角色失败:错误:必须是超级用户才能创建超级用户 [英] Logged in as postgres but getting the error createuser: creation of new role failed: ERROR: must be superuser to create superusers

查看:79
本文介绍了以 postgres 身份登录但收到错误 createuser:创建新角色失败:错误:必须是超级用户才能创建超级用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个超级用户,以便我可以创建一个数据库,但是我遇到了这个问题.我以 postgres 用户身份登录:

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:

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:创建新角色失败:错误:必须是超级用户才能创建超级用户

createuser: creation of new role failed: ERROR: must be superuser to create superusers

如果我尝试在 psql 中创建一个新用户然后让他成为超级用户,也会发生这种情况:

This also happens if I try to create a new user in psql and then make him a superuser:

$ psql -U postgres
psql (9.1.4)
Type "help" for help.

postgres=> create user glassboard
postgres-> ;
ERROR:  permission denied to create role

如何创建超级用户?

\du 在 postgres 中的输出:

output of \du in postgres:

postgres=> \du

                             List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
 main      | Superuser, Create role, Create DB, Replication | {}
 postgres  |                                                | {}

推荐答案

某些 OSX 软件包不创建 postgres 超级用户数据库帐户.超级用户的名称不同,在您的情况下是 main.

Some OSX packages don't create a postgres superuser database account. The superuser is named differently, in your case it's main.

当你在不指定数据库的情况下执行 psql -U main 时,它默认为与用户相同的名称.如果您没有名为 main 的数据库,请使用 -d 选项指示不同的数据库.

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.

如果您没有要连接的数据库,请使用 template1

If you have no database to connect to, use template1

psql -U main -d template1

如果您仍想授予 postgres 超级用户,请在登录 psql 后执行:

If still you want to grant superuser to postgres, do once logged inside psql:

alter user postgres superuser;

这篇关于以 postgres 身份登录但收到错误 createuser:创建新角色失败:错误:必须是超级用户才能创建超级用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆