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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:40:13  来源:igfitidea点击:

PostgreSQL error: Fatal: role "username" does not exist

postgresqlauthentication

提问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

h9uestis my account name, and I sudo apt-get installPostgreSQL 9.1 under this account.
Similar error persists for the rootaccount.

h9uest是我的账户名,我sudo apt-get install在这个账户下是PostgreSQL 9.1。
root帐户仍然存在类似的错误。

回答by Erwin Brandstetter

Use the operating system userpostgresto 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 (h9uestin your case):

使用操作系统用户postgres创建您的数据库 - 只要您尚未设置具有与您的同名操作系统用户相对应的必要权限的数据库角色(h9uest在您的情况下):

sudo -u postgres -i

As recommended hereor here.

正如这里这里推荐的那样。

Then try again. Type exitwhen done with operating as system user postgres.

然后再试一次。exit以系统用户身份完成操作后键入postgres

Orexecute the single command createuseras postgreswith sudo, like demonstrated by dreesin another answer.

或者createuserpostgreswithsudo一样执行单个命令,就像drees在另一个答案中所演示的那样

The point is to use the operating system user matching the database role of the same name to be granted access via identauthentication. postgresis 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 named postgres. 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:createfrom 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-getdoes 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,

工作方法,

  1. vi /etc/postgresql/9.3/main/pg_hba.conf
  2. local all postgres peerhere change peerto trust
  3. restart, sudo service postgresql restart

  4. now try, psql -U postgres

  1. vi /etc/postgresql/9.3/main/pg_hba.conf
  2. local all postgres peer这里改变信任
  3. 重新开始, sudo service postgresql restart

  4. 现在试试, 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