PostgreSQL 错误:致命:角色“用户名”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11919391/
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
PostgreSQL error: Fatal: role "username" does not exist
提问by h9uest
I'm setting up my PostgreSQL 9.1. I can't do anything with PostgreSQL: can't createdb
, can't createuser
; all operations return the error message
我正在设置我的 PostgreSQL 9.1。我不能用 PostgreSQL 做任何事:不能createdb
,不能createuser
;所有操作都返回错误信息
Fatal: role h9uest does not exist
h9uest
is my account name, and I sudo apt-get install
PostgreSQL 9.1 under this account.
Similar error persists for the root
account.
h9uest
是我的账户名,我sudo apt-get install
在这个账户下是PostgreSQL 9.1。
该root
帐户仍然存在类似的错误。
回答by Erwin Brandstetter
Use the operating system userpostgres
to create your database - as long as you haven't set up a databaserole with the necessary privileges that corresponds to your operating system user of the same name (h9uest
in your case):
使用操作系统用户postgres
创建您的数据库 - 只要您尚未设置具有与您的同名操作系统用户相对应的必要权限的数据库角色(h9uest
在您的情况下):
sudo -u postgres -i
Then try again. Type exit
when done with operating as system user postgres
.
然后再试一次。exit
以系统用户身份完成操作后键入postgres
。
Orexecute the single command createuser
as postgres
with sudo
, like demonstrated by dreesin another answer.
或者createuser
像postgres
withsudo
一样执行单个命令,就像drees在另一个答案中所演示的那样。
The point is to use the operating system user matching the database role of the same name to be granted access via ident
authentication. postgres
is the default operating system user to have initialized the database cluster. The manual:
关键是使用与同名数据库角色匹配的操作系统用户通过ident
身份验证授予访问权限。postgres
是初始化数据库集群的默认操作系统用户。手册:
In order to bootstrap the database system, a freshly initialized system always contains one predefined role. This role is always a “superuser”, and by default (unless altered when running
initdb
) it will have the same name as the operating system user that initialized the database cluster. Customarily, this role will be namedpostgres
. In order to create more roles you first have to connect as this initial role.
为了引导数据库系统,新初始化的系统总是包含一个预定义的角色。此角色始终是“超级用户”,默认情况下(除非在运行时更改
initdb
)它将与初始化数据库集群的操作系统用户同名。通常,此角色将命名为postgres
。为了创建更多角色,您首先必须作为这个初始角色进行连接。
I have heard of odd setups with non-standard user names or where the operating system user does not exist. You'd need to adapt your strategy there.
我听说过使用非标准用户名或操作系统用户不存在的奇怪设置。你需要在那里调整你的策略。
Read about database rolesand client authenticationin the manual.
回答by drees
After trying many other people's solutions, and without success, this answer finally helped me.
在尝试了许多其他人的解决方案并没有成功之后,这个答案终于帮助了我。
https://stackoverflow.com/a/16974197/2433309
https://stackoverflow.com/a/16974197/2433309
In short, running
简而言之,运行
sudo -u postgres createuser owning_user
creates a role with name owning_user (in this case, h9uest). After that you can run rake db:create
from the terminal under whatever account name you set up without having to enter into the Postgres environment.
创建一个名为 owning_user 的角色(在本例中为 h9uest)。之后,您可以使用rake db:create
您设置的任何帐户名称从终端运行,而无需进入 Postgres 环境。
回答by Mohammed Saleem
sudo su - postgres
psql template1
creating role on pgsql with privilege as "superuser"
在 pgsql 上创建具有“超级用户”特权的角色
CREATE ROLE username superuser;
eg. CREATE ROLE demo superuser;
Then create user
然后创建用户
CREATE USER username;
eg. CREATE USER demo;
Assign privilege to user
为用户分配权限
GRANT ROOT TO username;
And then enable login that user, so you can run e.g.: psql template1
, from normal $
terminal:
然后启用登录该用户,以便您可以psql template1
从普通$
终端运行 eg: :
ALTER ROLE username WITH LOGIN;
回答by Miles Erickson
Installing postgres using apt-get
does not create a user role or a database.
使用安装 postgresapt-get
不会创建用户角色或数据库。
To create a superuser role and a database for your personal user account:
要为您的个人用户帐户创建超级用户角色和数据库:
sudo -u postgres createuser -s $(whoami); createdb $(whoami)
sudo -u postgres createuser -s $(whoami); createdb $(whoami)
回答by mateusz.szymborski
This works for me:
这对我有用:
psql -h localhost -U postgres
回答by Mohideen bin Mohammed
Working method,
工作方法,
vi /etc/postgresql/9.3/main/pg_hba.conf
local all postgres peer
here change peerto trustrestart,
sudo service postgresql restart
now try,
psql -U postgres
vi /etc/postgresql/9.3/main/pg_hba.conf
local all postgres peer
这里改变对以信任重新开始,
sudo service postgresql restart
现在试试,
psql -U postgres
回答by Kalyan Halder Raaz
For version Postgres 9.5use following comand:
对于Postgres 9.5版本,请 使用以下命令:
psql -h localhost -U postgres
Hope this will help.
希望这会有所帮助。
回答by Abel
psql postgres
postgres=# CREATE ROLE username superuser;
postgres=# ALTER ROLE username WITH LOGIN;
回答by Robert Cambil
In local user prompt, not root user prompt, type
在本地用户提示中,而不是 root 用户提示中,键入
sudo -u postgres createuser <local username>
Then enter password for local user.
然后输入本地用户的密码。
Then enter the previous command that generated "role 'username' does not exist."
然后输入之前生成的命令“角色'用户名'不存在”。
Above steps solved the problem for me. If not, please send terminal messages for above steps.
以上步骤为我解决了问题。如果没有,请发送终端消息以进行上述步骤。
回答by Henry
I installed it on macOS and had to:
我将它安装在 macOS 上,并且必须:
cd /Applications/Postgres.app/Contents/Versions/9.5/bin
createuser -U postgres -s YOURUSERNAME
createdb YOURUSERNAME
Here's the source: https://github.com/PostgresApp/PostgresApp/issues/313#issuecomment-192461641
这是来源:https: //github.com/PostgresApp/PostgresApp/issues/313#issuecomment-192461641