"作用"在Postgresql中不存在

时间:2015-09-03 10:59:36

标签: postgresql

我正在阅读本教程here。以下命令以用户身份登录:

# login as user "user"
psql -U user

当我执行上述命令时,出现以下错误:

psql: FATAL:  role "user" does not exist

我在网上看到的唯一帮助是here,其中有以下内容:

  

致命:角色" myusername"不存在

     

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

     

创建合适的用户,或指定要连接的其他用户名   用。在命令行工具中,-U标志执行此操作。

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

2 个答案:

答案 0 :(得分:7)

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

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

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

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

createdb your_username -O your_username

然后你应该可以在psql中用

连接
psql -h localhost -U your_username

答案 1 :(得分:5)

请检查用户是否存在。

\dg

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

CREATE USER user WITH PASSWORD '<here you password>';
相关问题