Postgresql 中不存在“角色”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32373773/
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-10-21 02:00:55  来源:igfitidea点击:

"Role" does not exists in Postgresql

postgresql

提问by Alexander Solonik

I have been reading this tutorial. There is the below command to login as a user:

我一直在阅读本教程。有以下命令以用户身份登录:

# login as user "user"
psql -U user

when I execute the above command, I get an error saying the following:

当我执行上面的命令时,我收到一条错误消息:

psql: FATAL:  role "user" does not exist

The only help I saw online was here, the have said the following:

我在网上看到的唯一帮助是here,他们说了以下内容:

FATAL: role "myusername" does not exist

By default PostgreSQL connects to the PostgreSQL user with the same name as the current unix user. You have not created a PostgreSQL user by that name in your database.

Create a suitable user, or specify a different username to connect with. In the command line tools the -U flag does this.

致命:角色“myusername”不存在

默认情况下,PostgreSQL 连接到与当前 unix 用户同名的 PostgreSQL 用户。您尚未在数据库中使用该名称创建 PostgreSQL 用户。

创建一个合适的用户,或指定一个不同的用户名来连接。在命令行工具中, -U 标志执行此操作。

But I still don't quite understand why I am getting this error.

但我仍然不太明白为什么我会收到这个错误。

回答by Tommaso Di Bucchianico

You have first to login in a linux shell as the user postgresand than create new postgres user with the command createuser. The system user postgresis created automatically by the Postgres installer.

您必须首先以用户身份登录 linux shell,postgres然后使用命令创建新的 postgres 用户createuser。系统用户postgres由 Postgres 安装程序自动创建。

Execute this code in the console (change your_usernamewith a username of your choice):

在控制台中执行此代码(更改your_username为您选择的用户名):

sudo -u postgres -i
createuser -l -d -P your_username

Better you create a database with the same name too (this makes the login later easier):

最好也创建一个同名的数据库(这使得以后登录更容易):

createdb your_username -O your_username

Then you should be able to connect in psql with

然后你应该能够在 psql 中连接

psql -h localhost -U your_username

回答by René

Please check to see if the user exists.

请检查用户是否存在。

\dg

If not, you need what is missing in the tutorial and you edit it if necessary.

如果没有,您需要本教程中缺少的内容,并在必要时进行编辑。

CREATE USER user WITH PASSWORD '<here you password>';